Skip to content

Commit 7409b39

Browse files
author
carabasdaniel
authored
Merge pull request #1020 from lionce/FM-7590
FM-7950 stringify stdlib
2 parents ca61da2 + 96cbfd6 commit 7409b39

File tree

185 files changed

+8807
-4259
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

185 files changed

+8807
-4259
lines changed

README.md

+16-3,116
Large diffs are not rendered by default.

REFERENCE.md

+6,663
Large diffs are not rendered by default.

lib/facter/facter_dot_d.rb

+24-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
# A Facter plugin that loads facts from /etc/facter/facts.d
2-
# and /etc/puppetlabs/facter/facts.d.
1+
# @summary
2+
# A Facter plugin that loads facts from /etc/facter/facts.d
3+
# and /etc/puppetlabs/facter/facts.d.
34
#
45
# Facts can be in the form of JSON, YAML or Text files
56
# and any executable that returns key=value pairs.
@@ -13,20 +14,23 @@
1314
# fact scripts more often than is needed
1415
class Facter::Util::DotD
1516
require 'yaml'
16-
17+
# These will be nil if Puppet is not available.
1718
def initialize(dir = '/etc/facts.d', cache_file = File.join(Puppet[:libdir], 'facts_dot_d.cache'))
1819
@dir = dir
1920
@cache_file = cache_file
2021
@cache = nil
2122
@types = { '.txt' => :txt, '.json' => :json, '.yaml' => :yaml }
2223
end
2324

25+
# entries
2426
def entries
2527
Dir.entries(@dir).reject { |f| f =~ %r{^\.|\.ttl$} }.sort.map { |f| File.join(@dir, f) }
2628
rescue
2729
[]
2830
end
2931

32+
# fact_type
33+
# @param file
3034
def fact_type(file)
3135
extension = File.extname(file)
3236

@@ -37,6 +41,8 @@ def fact_type(file)
3741
type
3842
end
3943

44+
# txt_parser
45+
# @param file
4046
def txt_parser(file)
4147
File.readlines(file).each do |line|
4248
next unless line =~ %r{^([^=]+)=(.+)$}
@@ -51,6 +57,8 @@ def txt_parser(file)
5157
Facter.warn("Failed to handle #{file} as text facts: #{e.class}: #{e}")
5258
end
5359

60+
# json_parser
61+
# @param file
5462
def json_parser(file)
5563
begin
5664
require 'json'
@@ -68,6 +76,8 @@ def json_parser(file)
6876
Facter.warn("Failed to handle #{file} as json facts: #{e.class}: #{e}")
6977
end
7078

79+
# yaml_parser
80+
# @param file
7181
def yaml_parser(file)
7282
require 'yaml'
7383

@@ -80,6 +90,8 @@ def yaml_parser(file)
8090
Facter.warn("Failed to handle #{file} as yaml facts: #{e.class}: #{e}")
8191
end
8292

93+
# script_parser
94+
# @param file
8395
def script_parser(file)
8496
result = cache_lookup(file)
8597
ttl = cache_time(file)
@@ -110,19 +122,24 @@ def script_parser(file)
110122
Facter.debug(e.backtrace.join("\n\t"))
111123
end
112124

125+
# cache_save
113126
def cache_save!
114127
cache = load_cache
115128
File.open(@cache_file, 'w', 0o600) { |f| f.write(YAML.dump(cache)) }
116129
rescue # rubocop:disable Lint/HandleExceptions
117130
end
118131

132+
# cache_store
133+
# @param file
119134
def cache_store(file, data)
120135
load_cache
121136

122137
@cache[file] = { :data => data, :stored => Time.now.to_i }
123138
rescue # rubocop:disable Lint/HandleExceptions
124139
end
125140

141+
# cache_lookup
142+
# @param file
126143
def cache_lookup(file)
127144
cache = load_cache
128145

@@ -140,6 +157,8 @@ def cache_lookup(file)
140157
return nil
141158
end
142159

160+
# cache_time
161+
# @param file
143162
def cache_time(file)
144163
meta = file + '.ttl'
145164

@@ -148,6 +167,7 @@ def cache_time(file)
148167
return 0
149168
end
150169

170+
# load_cache
151171
def load_cache
152172
@cache ||= if File.exist?(@cache_file)
153173
YAML.load_file(@cache_file)
@@ -161,6 +181,7 @@ def load_cache
161181
return @cache
162182
end
163183

184+
# create
164185
def create
165186
entries.each do |fact|
166187
type = fact_type(fact)

lib/facter/package_provider.rb

+2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
require 'puppet/type'
1111
require 'puppet/type/package'
1212

13+
# These will be nil if Puppet is not available.
1314
Facter.add(:package_provider) do
15+
# Instantiates a dummy package resource and return the provider
1416
setcode do
1517
if defined? Gem && Gem::Version.new(Facter.value(:puppetversion).split(' ')[0]) >= Gem::Version.new('3.6')
1618
Puppet::Type.type(:package).newpackage(:name => 'dummy', :allow_virtual => 'true')[:provider].to_s

lib/facter/pe_version.rb

+5
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#
99
# Caveats:
1010
#
11+
# Fact: pe_version
1112
Facter.add('pe_version') do
1213
setcode do
1314
puppet_ver = Facter.value('puppetversion')
@@ -20,6 +21,7 @@
2021
end
2122
end
2223

24+
# Fact: is_pe
2325
Facter.add('is_pe') do
2426
setcode do
2527
if Facter.value(:pe_version).to_s.empty?
@@ -30,6 +32,7 @@
3032
end
3133
end
3234

35+
# Fact: pe_major_version
3336
Facter.add('pe_major_version') do
3437
confine :is_pe => true
3538
setcode do
@@ -40,6 +43,7 @@
4043
end
4144
end
4245

46+
# Fact: pe_minor_version
4347
Facter.add('pe_minor_version') do
4448
confine :is_pe => true
4549
setcode do
@@ -50,6 +54,7 @@
5054
end
5155
end
5256

57+
# Fact: pe_patch_version
5358
Facter.add('pe_patch_version') do
5459
confine :is_pe => true
5560
setcode do

lib/facter/puppet_settings.rb

+3-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
load rb_file if File.exist?(rb_file) || raise(e)
1717
end
1818

19-
# These will be nil if Puppet is not available.
19+
# Facter fact returns the value of the Puppet vardir
2020
Facter.add(:puppet_vardir) do
2121
setcode do
2222
Facter::Util::PuppetSettings.with_puppet do
@@ -25,6 +25,7 @@
2525
end
2626
end
2727

28+
# Facter fact returns the value of the Puppet environment path
2829
Facter.add(:puppet_environmentpath) do
2930
setcode do
3031
Facter::Util::PuppetSettings.with_puppet do
@@ -33,6 +34,7 @@
3334
end
3435
end
3536

37+
# Facter fact returns the value of the Puppet server
3638
Facter.add(:puppet_server) do
3739
setcode do
3840
Facter::Util::PuppetSettings.with_puppet do

lib/facter/root_home.rb

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
# A facter fact to determine the root home directory.
2-
# This varies on PE supported platforms and may be
3-
# reconfigured by the end user.
1+
# root_home.rb
42
module Facter::Util::RootHome
3+
# @summary
4+
# A facter fact to determine the root home directory.
5+
# This varies on PE supported platforms and may be
6+
# reconfigured by the end user.
57
class << self
8+
# determines the root home directory
69
def returnt_root_home
710
root_ent = Facter::Util::Resolution.exec('getent passwd root')
811
# The home directory is the sixth element in the passwd entry

lib/puppet/functions/deprecation.rb

+11-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
1-
# Function to print deprecation warnings, Logs a warning once for a given key. The uniqueness key - can appear once.
2-
# The msg is the message text including any positional information that is formatted by the user/caller of the method.
3-
# It is affected by the puppet setting 'strict', which can be set to :error (outputs as an error message),
4-
# :off (no message / error is displayed) and :warning (default, outputs a warning) *Type*: String, String.
1+
# Function to print deprecation warnings, Logs a warning once for a given key.
2+
#
3+
# The uniqueness key - can appear once.
4+
# The msg is the message text including any positional information that is formatted by the
5+
# user/caller of the method.
6+
# It is affected by the puppet setting 'strict', which can be set to :error
7+
# (outputs as an error message), :off (no message / error is displayed) and :warning
8+
# (default, outputs a warning) *Type*: String, String.
59
#
6-
710
Puppet::Functions.create_function(:deprecation) do
11+
# @param key
12+
# @param message
13+
# @return deprecated warnings
814
dispatch :deprecation do
915
param 'String', :key
1016
param 'String', :message

lib/puppet/functions/fact.rb

+12-6
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,25 @@
1-
# Digs into the facts hash using dot-notation
1+
# @summary
2+
# Digs into the facts hash using dot-notation
23
#
3-
# Example usage:
4+
# Supports the use of dot-notation for referring to structured facts. If a fact requested
5+
# does not exist, returns Undef.
46
#
7+
# @example Example usage:
58
# fact('osfamily')
69
# fact('os.architecture')
710
#
8-
# Array indexing:
9-
#
11+
# @example Array indexing:
1012
# fact('mountpoints."/dev".options.1')
1113
#
12-
# Fact containing a "." in the name:
13-
#
14+
# @example Fact containing a "." in the name:
1415
# fact('vmware."VRA.version"')
1516
#
1617
Puppet::Functions.create_function(:fact) do
18+
# @param fact_name
19+
# The name of the fact to check
20+
#
21+
# @return
22+
# All information retrieved on the given fact_name
1723
dispatch :fact do
1824
param 'String', :fact_name
1925
end

lib/puppet/functions/is_a.rb

+24-14
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,35 @@
1-
# Boolean check to determine whether a variable is of a given data type. This is equivalent to the `=~` type checks.
1+
# @summary
2+
# Boolean check to determine whether a variable is of a given data type.
3+
# This is equivalent to the `=~` type checks.
24
#
3-
# @example how to check a data type
5+
# @example Example Usage:
46
# # check a data type
5-
# foo = 3
6-
# $bar = [1,2,3]
7-
# $baz = 'A string!'
7+
# foo = 3
8+
# $bar = [1,2,3]
9+
# $baz = 'A string!'
810
#
9-
# if $foo.is_a(Integer) {
10-
# notify { 'foo!': }
11-
# }
12-
# if $bar.is_a(Array) {
13-
# notify { 'bar!': }
14-
# }
15-
# if $baz.is_a(String) {
16-
# notify { 'baz!': }
17-
# }
11+
# if $foo.is_a(Integer) {
12+
# notify { 'foo!': }
13+
# }
14+
# if $bar.is_a(Array) {
15+
# notify { 'bar!': }
16+
# }
17+
# if $baz.is_a(String) {
18+
# notify { 'baz!': }
19+
# }
1820
#
1921
# See the documentation for "The Puppet Type System" for more information about types.
2022
# See the `assert_type()` function for flexible ways to assert the type of a value.
2123
#
2224
Puppet::Functions.create_function(:is_a) do
25+
# @param value
26+
# The value to be checked
27+
#
28+
# @param type
29+
# The expected type
30+
#
31+
# @return [Boolean]
32+
# Return's `true` or `false`.
2333
dispatch :is_a do
2434
param 'Any', :value
2535
param 'Type', :type

lib/puppet/functions/is_absolute_path.rb

+10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
1+
# @summary
2+
# Wrapper that calls the Puppet 3.x funtion of the same name.
13
Puppet::Functions.create_function(:is_absolute_path) do
4+
# @param scope
5+
# The main value that will be passed to the wrapped method
6+
#
7+
# @param args
8+
# Any additional values that are to be passed to the wrapped method
9+
#
10+
# @return [Boolea]
11+
# A boolean value returned from the called 3.x function.
212
dispatch :deprecation_gen do
313
param 'Any', :scope
414
repeated_param 'Any', :args

lib/puppet/functions/is_array.rb

+10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
1+
# @summary
2+
# Wrapper that calls the Puppet 3.x funtion of the same name.
13
Puppet::Functions.create_function(:is_array) do
4+
# @param scope
5+
# The main value that will be passed to the wrapped method
6+
#
7+
# @param args
8+
# Any additional values that are to be passed to the wrapped method
9+
#
10+
# @return [Boolea]
11+
# A boolean value returned from the called 3.x function.
212
dispatch :deprecation_gen do
313
param 'Any', :scope
414
repeated_param 'Any', :args

lib/puppet/functions/is_bool.rb

+10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
1+
# @summary
2+
# Wrapper that calls the Puppet 3.x funtion of the same name.
13
Puppet::Functions.create_function(:is_bool) do
4+
# @param scope
5+
# The main value that will be passed to the wrapped method
6+
#
7+
# @param args
8+
# Any additional values that are to be passed to the wrapped method
9+
#
10+
# @return [Boolea]
11+
# A boolean value returned from the called 3.x function.
212
dispatch :deprecation_gen do
313
param 'Any', :scope
414
repeated_param 'Any', :args

lib/puppet/functions/is_float.rb

+10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
1+
# @summary
2+
# Wrapper that calls the Puppet 3.x funtion of the same name.
13
Puppet::Functions.create_function(:is_float) do
4+
# @param scope
5+
# The main value that will be passed to the wrapped method
6+
#
7+
# @param args
8+
# Any additional values that are to be passed to the wrapped method
9+
#
10+
# @return [Boolea]
11+
# A boolean value returned from the called 3.x function.
212
dispatch :deprecation_gen do
313
param 'Any', :scope
414
repeated_param 'Any', :args

lib/puppet/functions/is_ip_address.rb

+10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
1+
# @summary
2+
# Wrapper that calls the Puppet 3.x funtion of the same name.
13
Puppet::Functions.create_function(:is_ip_address) do
4+
# @param scope
5+
# The main value that will be passed to the wrapped method
6+
#
7+
# @param args
8+
# Any additional values that are to be passed to the wrapped method
9+
#
10+
# @return [Boolea]
11+
# A boolean value returned from the called 3.x function.
212
dispatch :deprecation_gen do
313
param 'Any', :scope
414
repeated_param 'Any', :args

0 commit comments

Comments
 (0)