facter 1.7.6 → 2.0.1.rc1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of facter might be problematic. Click here for more details.

Files changed (155) hide show
  1. checksums.yaml +7 -0
  2. data/COMMITTERS.md +194 -0
  3. data/CONTRIBUTING.md +63 -235
  4. data/Gemfile +12 -8
  5. data/README.md +1 -2
  6. data/Rakefile +1 -1
  7. data/bin/facter +0 -4
  8. data/ext/build_defaults.yaml +2 -2
  9. data/ext/project_data.yaml +18 -0
  10. data/install.rb +1 -16
  11. data/lib/facter.rb +171 -171
  12. data/lib/facter/application.rb +65 -54
  13. data/lib/facter/core/aggregate.rb +220 -0
  14. data/lib/facter/core/directed_graph.rb +46 -0
  15. data/lib/facter/core/execution.rb +100 -0
  16. data/lib/facter/core/execution/base.rb +73 -0
  17. data/lib/facter/core/execution/posix.rb +50 -0
  18. data/lib/facter/core/execution/windows.rb +57 -0
  19. data/lib/facter/core/logging.rb +169 -0
  20. data/lib/facter/core/resolvable.rb +94 -0
  21. data/lib/facter/core/suitable.rb +117 -0
  22. data/lib/facter/domain.rb +15 -9
  23. data/lib/facter/filesystems.rb +1 -1
  24. data/lib/facter/hardwaremodel.rb +1 -1
  25. data/lib/facter/hostname.rb +3 -3
  26. data/lib/facter/interfaces.rb +6 -1
  27. data/lib/facter/ipaddress.rb +2 -2
  28. data/lib/facter/kernel.rb +1 -1
  29. data/lib/facter/kernelrelease.rb +1 -1
  30. data/lib/facter/ldom.rb +1 -1
  31. data/lib/facter/lsbdistcodename.rb +1 -1
  32. data/lib/facter/lsbdistdescription.rb +1 -1
  33. data/lib/facter/lsbdistid.rb +1 -1
  34. data/lib/facter/lsbdistrelease.rb +1 -1
  35. data/lib/facter/lsbrelease.rb +1 -1
  36. data/lib/facter/macaddress.rb +1 -14
  37. data/lib/facter/macosx.rb +2 -2
  38. data/lib/facter/memory.rb +8 -19
  39. data/lib/facter/operatingsystem.rb +1 -1
  40. data/lib/facter/operatingsystemrelease.rb +34 -1
  41. data/lib/facter/physicalprocessorcount.rb +6 -6
  42. data/lib/facter/processor.rb +11 -10
  43. data/lib/facter/selinux.rb +4 -15
  44. data/lib/facter/ssh.rb +5 -2
  45. data/lib/facter/util/architecture.rb +2 -2
  46. data/lib/facter/util/collection.rb +42 -38
  47. data/lib/facter/util/config.rb +19 -9
  48. data/lib/facter/util/confine.rb +34 -4
  49. data/lib/facter/util/ec2.rb +1 -1
  50. data/lib/facter/util/fact.rb +108 -36
  51. data/lib/facter/util/file_read.rb +7 -6
  52. data/lib/facter/util/formatter.rb +38 -0
  53. data/lib/facter/util/ip.rb +3 -3
  54. data/lib/facter/util/loader.rb +62 -42
  55. data/lib/facter/util/macosx.rb +7 -8
  56. data/lib/facter/util/manufacturer.rb +3 -3
  57. data/lib/facter/util/memory.rb +13 -13
  58. data/lib/facter/util/monkey_patches.rb +0 -31
  59. data/lib/facter/util/netmask.rb +3 -3
  60. data/lib/facter/util/normalization.rb +94 -0
  61. data/lib/facter/util/nothing_loader.rb +3 -6
  62. data/lib/facter/util/parser.rb +3 -5
  63. data/lib/facter/util/plist/generator.rb +1 -1
  64. data/lib/facter/util/processor.rb +15 -15
  65. data/lib/facter/util/resolution.rb +112 -289
  66. data/lib/facter/util/solaris_zones.rb +4 -4
  67. data/lib/facter/util/uptime.rb +8 -3
  68. data/lib/facter/util/values.rb +67 -1
  69. data/lib/facter/util/virtual.rb +10 -10
  70. data/lib/facter/util/xendomains.rb +1 -1
  71. data/lib/facter/version.rb +42 -39
  72. data/lib/facter/virtual.rb +6 -7
  73. data/lib/facter/zfs_version.rb +3 -3
  74. data/lib/facter/zpool_version.rb +3 -3
  75. data/spec/fixtures/unit/netmask/darwin_10_8_5.txt +30 -0
  76. data/spec/unit/application_spec.rb +46 -1
  77. data/spec/unit/core/aggregate_spec.rb +125 -0
  78. data/spec/unit/core/directed_graph_spec.rb +79 -0
  79. data/spec/unit/core/execution/base_spec.rb +119 -0
  80. data/spec/unit/core/execution/posix_spec.rb +86 -0
  81. data/spec/unit/core/execution/windows_spec.rb +106 -0
  82. data/spec/unit/core/execution_spec.rb +37 -0
  83. data/spec/unit/core/logging_spec.rb +104 -0
  84. data/spec/unit/core/resolvable_spec.rb +81 -0
  85. data/spec/unit/core/suitable_spec.rb +96 -0
  86. data/spec/unit/domain_spec.rb +5 -5
  87. data/spec/unit/facter_spec.rb +61 -222
  88. data/spec/unit/filesystems_spec.rb +2 -2
  89. data/spec/unit/hardwareisa_spec.rb +5 -5
  90. data/spec/unit/hardwaremodel_spec.rb +1 -1
  91. data/spec/unit/hostname_spec.rb +4 -4
  92. data/spec/unit/id_spec.rb +3 -3
  93. data/spec/unit/interfaces_spec.rb +10 -0
  94. data/spec/unit/ipaddress6_spec.rb +4 -4
  95. data/spec/unit/ipaddress_spec.rb +1 -1
  96. data/spec/unit/kernel_spec.rb +2 -2
  97. data/spec/unit/kernelmajversion_spec.rb +1 -1
  98. data/spec/unit/kernelrelease_spec.rb +4 -4
  99. data/spec/unit/kernelversion_spec.rb +2 -2
  100. data/spec/unit/ldom_spec.rb +2 -2
  101. data/spec/unit/lsbdistcodename_spec.rb +2 -2
  102. data/spec/unit/lsbdistdescription_spec.rb +2 -2
  103. data/spec/unit/lsbdistid_spec.rb +2 -2
  104. data/spec/unit/lsbdistrelease_spec.rb +2 -2
  105. data/spec/unit/lsbrelease_spec.rb +2 -2
  106. data/spec/unit/manufacturer_spec.rb +1 -1
  107. data/spec/unit/memory_spec.rb +24 -31
  108. data/spec/unit/netmask_spec.rb +9 -0
  109. data/spec/unit/operatingsystem_spec.rb +1 -1
  110. data/spec/unit/operatingsystemrelease_spec.rb +62 -4
  111. data/spec/unit/physicalprocessorcount_spec.rb +10 -10
  112. data/spec/unit/processor_spec.rb +11 -11
  113. data/spec/unit/selinux_spec.rb +2 -8
  114. data/spec/unit/ssh_spec.rb +3 -2
  115. data/spec/unit/uniqueid_spec.rb +3 -3
  116. data/spec/unit/util/collection_spec.rb +37 -35
  117. data/spec/unit/util/config_spec.rb +20 -0
  118. data/spec/unit/util/confine_spec.rb +21 -0
  119. data/spec/unit/util/directory_loader_spec.rb +1 -0
  120. data/spec/unit/util/ec2_spec.rb +6 -6
  121. data/spec/unit/util/fact_spec.rb +92 -90
  122. data/spec/unit/util/ip_spec.rb +2 -2
  123. data/spec/unit/util/loader_spec.rb +127 -186
  124. data/spec/unit/util/macaddress_spec.rb +2 -2
  125. data/spec/unit/util/macosx_spec.rb +8 -8
  126. data/spec/unit/util/manufacturer_spec.rb +3 -3
  127. data/spec/unit/util/normalization_spec.rb +113 -0
  128. data/spec/unit/util/parser_spec.rb +25 -3
  129. data/spec/unit/util/processor_spec.rb +2 -2
  130. data/spec/unit/util/resolution_spec.rb +60 -631
  131. data/spec/unit/util/solaris_zones_spec.rb +5 -5
  132. data/spec/unit/util/uptime_spec.rb +1 -1
  133. data/spec/unit/util/values_spec.rb +131 -0
  134. data/spec/unit/util/virtual_spec.rb +16 -16
  135. data/spec/unit/util/xendomains_spec.rb +2 -2
  136. data/spec/unit/virtual_spec.rb +39 -39
  137. data/spec/unit/zfs_version_spec.rb +11 -11
  138. data/spec/unit/zonename_spec.rb +2 -2
  139. data/spec/unit/zones_spec.rb +1 -1
  140. data/spec/unit/zpool_version_spec.rb +11 -11
  141. metadata +466 -447
  142. data/lib/facter/util/cfpropertylist.rb +0 -6
  143. data/lib/facter/util/cfpropertylist/LICENSE +0 -19
  144. data/lib/facter/util/cfpropertylist/README +0 -44
  145. data/lib/facter/util/cfpropertylist/Rakefile +0 -44
  146. data/lib/facter/util/cfpropertylist/THANKS +0 -7
  147. data/lib/facter/util/cfpropertylist/lib/cfpropertylist.rb +0 -6
  148. data/lib/facter/util/cfpropertylist/lib/rbBinaryCFPropertyList.rb +0 -562
  149. data/lib/facter/util/cfpropertylist/lib/rbCFPlistError.rb +0 -26
  150. data/lib/facter/util/cfpropertylist/lib/rbCFPropertyList.rb +0 -407
  151. data/lib/facter/util/cfpropertylist/lib/rbCFTypes.rb +0 -244
  152. data/lib/facter/util/cfpropertylist/lib/rbLibXMLParser.rb +0 -135
  153. data/lib/facter/util/cfpropertylist/lib/rbNokogiriParser.rb +0 -140
  154. data/lib/facter/util/cfpropertylist/lib/rbREXMLParser.rb +0 -136
  155. data/spec/unit/util/monkey_patches_spec.rb +0 -42
data/Gemfile CHANGED
@@ -20,14 +20,18 @@ group :development, :test do
20
20
  gem 'puppetlabs_spec_helper'
21
21
  end
22
22
 
23
- platform :mswin, :mingw do
24
- gem "ffi", "1.9.0", :require => false
25
- gem "sys-admin", "1.5.6", :require => false
26
- gem "win32-api", "1.4.8", :require => false
27
- gem "win32-dir", "0.4.3", :require => false
28
- gem "windows-api", "0.4.2", :require => false
29
- gem "windows-pr", "1.2.2", :require => false
30
- gem "win32console", "1.3.2", :require => false
23
+ require 'yaml'
24
+ data = YAML.load_file(File.join(File.dirname(__FILE__), 'ext', 'project_data.yaml'))
25
+ bundle_platforms = data['bundle_platforms']
26
+ data['gem_platform_dependencies'].each_pair do |gem_platform, info|
27
+ if bundle_deps = info['gem_runtime_dependencies']
28
+ bundle_platform = bundle_platforms[gem_platform] or raise "Missing bundle_platform"
29
+ platform(bundle_platform.intern) do
30
+ bundle_deps.each_pair do |name, version|
31
+ gem(name, version, :require => false)
32
+ end
33
+ end
34
+ end
31
35
  end
32
36
 
33
37
  gem 'facter', ">= 1.0.0", :path => File.expand_path("..", __FILE__)
data/README.md CHANGED
@@ -3,8 +3,7 @@ Facter
3
3
 
4
4
  This package is largely meant to be a library for collecting facts about your
5
5
  system. These facts are mostly strings (i.e., not numbers), and are things
6
- like the output of `uname`, public ssh and cfengine keys, the number of
7
- processors, etc.
6
+ like the output of `uname`, public ssh keys, the number of processors, etc.
8
7
 
9
8
  See `bin/facter` for an example of the interface.
10
9
 
data/Rakefile CHANGED
@@ -7,6 +7,7 @@ require 'facter/version'
7
7
  $LOAD_PATH << File.join(File.dirname(__FILE__), 'tasks')
8
8
 
9
9
  require 'rake'
10
+ Dir['tasks/**/*.rake'].each { |t| load t }
10
11
 
11
12
  begin
12
13
  load File.join(File.dirname(__FILE__), 'ext', 'packaging', 'packaging.rake')
@@ -23,7 +24,6 @@ end
23
24
  end
24
25
  end
25
26
 
26
- Dir['tasks/**/*.rake'].each { |t| load t }
27
27
 
28
28
  build_defs_file = 'ext/build_defaults.yaml'
29
29
  if File.exist?(build_defs_file)
data/bin/facter CHANGED
@@ -1,9 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- # For security reasons, ensure that '.' is not on the load path
4
- # This is primarily for 1.8.7 since 1.9.2+ doesn't put '.' on the load path
5
- $LOAD_PATH.delete '.'
6
-
7
3
  # Bundler and rubygems maintain a set of directories from which to
8
4
  # load gems. If Bundler is loaded, let it determine what can be
9
5
  # loaded. If it's not loaded, then use rubygems. But do this before
@@ -2,14 +2,14 @@
2
2
  packaging_url: 'git://github.com/puppetlabs/packaging.git --branch=master'
3
3
  packaging_repo: 'packaging'
4
4
  default_cow: 'base-squeeze-i386.cow'
5
- cows: 'base-lucid-i386.cow base-lucid-amd64.cow base-precise-i386.cow base-precise-amd64.cow base-quantal-i386.cow base-quantal-amd64.cow base-saucy-i386.cow base-saucy-amd64.cow base-squeeze-i386.cow base-squeeze-amd64.cow base-stable-i386.cow base-stable-amd64.cow base-testing-i386.cow base-testing-amd64.cow base-wheezy-i386.cow base-wheezy-amd64.cow'
5
+ cows: 'base-lucid-i386.cow base-lucid-amd64.cow base-precise-i386.cow base-precise-amd64.cow base-quantal-i386.cow base-quantal-amd64.cow base-raring-i386.cow base-raring-amd64.cow base-saucy-i386.cow base-saucy-amd64.cow base-sid-i386.cow base-sid-amd64.cow base-squeeze-i386.cow base-squeeze-amd64.cow base-stable-i386.cow base-stable-amd64.cow base-testing-i386.cow base-testing-amd64.cow base-unstable-i386.cow base-unstable-amd64.cow base-wheezy-i386.cow base-wheezy-amd64.cow'
6
6
  pbuild_conf: '/etc/pbuilderrc'
7
7
  packager: 'puppetlabs'
8
8
  gpg_name: 'info@puppetlabs.com'
9
9
  gpg_key: '4BD6EC30'
10
10
  sign_tar: FALSE
11
11
  # a space separated list of mock configs
12
- final_mocks: 'pl-el-5-i386 pl-el-5-x86_64 pl-el-6-i386 pl-el-6-x86_64 pl-el-7-x86_64 pl-fedora-19-i386 pl-fedora-19-x86_64 pl-fedora-20-i386 pl-fedora-20-x86_64'
12
+ final_mocks: 'pl-el-5-i386 pl-el-5-x86_64 pl-el-6-i386 pl-el-6-x86_64 pl-el-7-x86_64 pl-fedora-18-i386 pl-fedora-18-x86_64 pl-fedora-19-i386 pl-fedora-19-x86_64 pl-fedora-20-i386 pl-fedora-20-x86_64'
13
13
  yum_host: 'yum.puppetlabs.com'
14
14
  yum_repo_path: '/opt/repository/yum/'
15
15
  build_gem: TRUE
@@ -13,3 +13,21 @@ gem_require_path: 'lib'
13
13
  gem_test_files: 'spec/**/*'
14
14
  gem_executables: 'facter'
15
15
  gem_default_executables: 'facter'
16
+ gem_platform_dependencies:
17
+ universal-darwin:
18
+ gem_runtime_dependencies:
19
+ CFPropertyList: '~> 2.2.6'
20
+ x86-mingw32:
21
+ gem_runtime_dependencies:
22
+ ffi: '1.9.0'
23
+ sys-admin: '1.5.6'
24
+ win32-api: '1.4.8'
25
+ win32-dir: '~> 0.4.3'
26
+ windows-api: '~> 0.4.2'
27
+ windows-pr: '~> 1.2.2'
28
+ win32console: '~> 1.3.2'
29
+ bundle_platforms:
30
+ universal-darwin: ruby
31
+ x86-mingw32: mingw
32
+ pre_tasks:
33
+ 'package:apple': 'cfpropertylist'
data/install.rb CHANGED
@@ -160,10 +160,6 @@ def prepare_installation
160
160
  opts.on('--[no-]man', 'Presents the creation of man pages.', 'Default on.') do |onman|
161
161
  InstallOptions.man = onman
162
162
  end
163
- opts.on('--[no-]tests', 'Prevents the execution of unit tests.', 'Default off.') do |ontest|
164
- InstallOptions.tests = ontest
165
- warn "The tests flag has never worked in Facter, is deprecated as of Nov 29, 2012, and will be removed in a future release of Facter."
166
- end
167
163
  opts.on('--destdir[=OPTIONAL]', 'Installation prefix for all targets', 'Default essentially /') do |destdir|
168
164
  InstallOptions.destdir = destdir
169
165
  end
@@ -233,18 +229,7 @@ def prepare_installation
233
229
  mandir = RbConfig::CONFIG['mandir']
234
230
  end
235
231
 
236
- # To be deprecated once people move over to using --destdir option
237
- if (destdir = ENV['DESTDIR'])
238
- warn "DESTDIR is deprecated. Use --destdir instead."
239
- bindir = join(destdir, bindir)
240
- mandir = join(destdir, mandir)
241
- sitelibdir = join(destdir, sitelibdir)
242
-
243
- FileUtils.makedirs(bindir)
244
- FileUtils.makedirs(mandir)
245
- FileUtils.makedirs(sitelibdir)
246
- # This is the new way forward
247
- elsif (destdir = InstallOptions.destdir)
232
+ if (destdir = InstallOptions.destdir)
248
233
  bindir = join(destdir, bindir)
249
234
  mandir = join(destdir, mandir)
250
235
  sitelibdir = join(destdir, sitelibdir)
@@ -16,8 +16,20 @@
16
16
 
17
17
  require 'facter/version'
18
18
 
19
+ # Functions as a hash of 'facts' about your system system, such as MAC
20
+ # address, IP address, architecture, etc.
21
+ #
22
+ # @example Retrieve a fact
23
+ # puts Facter['operatingsystem'].value
24
+ #
25
+ # @example Retrieve all facts
26
+ # Facter.to_hash
27
+ # => { "kernel"=>"Linux", "uptime_days"=>0, "ipaddress"=>"10.0.0.1" }
28
+ #
29
+ # @api public
19
30
  module Facter
20
- # This is just so the other classes have the constant.
31
+ # Most core functionality of facter is implemented in `Facter::Util`.
32
+ # @api public
21
33
  module Util; end
22
34
 
23
35
  require 'facter/util/fact'
@@ -27,28 +39,15 @@ module Facter
27
39
  include Comparable
28
40
  include Enumerable
29
41
 
30
- # = Facter
31
- # Functions as a hash of 'facts' you might care about about your
32
- # system, such as mac address, IP address, Video card, etc.
33
- # returns them dynamically
34
-
35
- # == Synopsis
36
- #
37
- # Generally, treat <tt>Facter</tt> as a hash:
38
- # == Example
39
- # require 'facter'
40
- # puts Facter['operatingsystem']
41
- #
42
-
43
- GREEN = ""
44
- RESET = ""
45
- @@debug = 0
46
- @@timing = 0
47
- @@messages = {}
48
- @@debug_messages = {}
42
+ require 'facter/core/logging'
43
+ extend Facter::Core::Logging
49
44
 
50
45
  # module methods
51
46
 
47
+ # Accessor for the collection object which holds all the facts
48
+ # @return [Facter::Util::Collection] the collection of facts
49
+ #
50
+ # @api private
52
51
  def self.collection
53
52
  unless defined?(@collection) and @collection
54
53
  @collection = Facter::Util::Collection.new(
@@ -58,39 +57,9 @@ module Facter
58
57
  @collection
59
58
  end
60
59
 
61
- # Add some debugging
62
- def self.debug(string)
63
- if string.nil?
64
- return
65
- end
66
- if self.debugging?
67
- puts GREEN + string + RESET
68
- end
69
- end
70
-
71
- # Debug once.
72
- def self.debugonce(msg)
73
- if msg and not msg.empty? and @@debug_messages[msg].nil?
74
- @@debug_messages[msg] = true
75
- debug(msg)
76
- end
77
- end
78
-
79
- def self.debugging?
80
- @@debug != 0
81
- end
82
-
83
- # show the timing information
84
- def self.show_time(string)
85
- puts "#{GREEN}#{string}#{RESET}" if string and Facter.timing?
86
- end
87
-
88
- def self.timing?
89
- @@timing != 0
90
- end
91
-
92
- # Facter.json? is meant to provide a lightweight way to check if the JSON
93
- # "feature" is available.
60
+ # Returns whether the JSON "feature" is available.
61
+ #
62
+ # @api private
94
63
  def self.json?
95
64
  begin
96
65
  require 'json'
@@ -100,34 +69,107 @@ module Facter
100
69
  end
101
70
  end
102
71
 
103
- # Return a fact object by name. If you use this, you still have to call
104
- # 'value' on it to retrieve the actual value.
72
+ # Returns a fact object by name. If you use this, you still have to
73
+ # call {Facter::Util::Fact#value `value`} on it to retrieve the actual
74
+ # value.
75
+ #
76
+ # @param name [String] the name of the fact
77
+ #
78
+ # @return [Facter::Util::Fact, nil] The fact object, or nil if no fact
79
+ # is found.
80
+ #
81
+ # @api public
105
82
  def self.[](name)
106
83
  collection.fact(name)
107
84
  end
108
85
 
109
- class << self
110
- [:fact, :flush, :list, :value].each do |method|
111
- define_method(method) do |*args|
112
- collection.send(method, *args)
113
- end
114
- end
86
+ # (see [])
87
+ def self.fact(name)
88
+ collection.fact(name)
89
+ end
115
90
 
116
- [:list, :to_hash].each do |method|
117
- define_method(method) do |*args|
118
- collection.load_all
119
- collection.send(method, *args)
120
- end
121
- end
91
+ # Flushes cached values for all facts. This does not cause code to be
92
+ # reloaded; it only clears the cached results.
93
+ #
94
+ # @return [void]
95
+ #
96
+ # @api public
97
+ def self.flush
98
+ collection.flush
99
+ end
100
+
101
+ # Lists all fact names
102
+ #
103
+ # @return [Array<String>] array of fact names
104
+ #
105
+ # @api public
106
+ def self.list
107
+ collection.list
108
+ end
109
+
110
+ # Gets the value for a fact. Returns `nil` if no such fact exists.
111
+ #
112
+ # @param name [String] the fact name
113
+ # @return [Object, nil] the value of the fact, or nil if no fact is
114
+ # found
115
+ #
116
+ # @api public
117
+ def self.value(name)
118
+ collection.value(name)
119
+ end
120
+
121
+ # Gets a hash mapping fact names to their values
122
+ #
123
+ # @return [Hash{String => Object}] the hash of fact names and values
124
+ #
125
+ # @api public
126
+ def self.to_hash
127
+ collection.load_all
128
+ collection.to_hash
122
129
  end
123
130
 
131
+ # Define a new fact or extend an existing fact.
132
+ #
133
+ # @param name [Symbol] The name of the fact to define
134
+ # @param options [Hash] A hash of options to set on the fact
135
+ #
136
+ # @return [Facter::Util::Fact] The fact that was defined
137
+ #
138
+ # @api public
139
+ # @see {Facter::Util::Collection#define_fact}
140
+ def self.define_fact(name, options = {}, &block)
141
+ collection.define_fact(name, options, &block)
142
+ end
124
143
 
125
- # Add a resolution mechanism for a named fact. This does not distinguish
126
- # between adding a new fact and adding a new way to resolve a fact.
144
+ # Adds a {Facter::Util::Resolution resolution} mechanism for a named
145
+ # fact. This does not distinguish between adding a new fact and adding
146
+ # a new way to resolve a fact.
147
+ #
148
+ # @overload add(name, options = {}, { || ... })
149
+ # @param name [String] the fact name
150
+ # @param options [Hash] optional parameters for the fact - attributes
151
+ # of {Facter::Util::Fact} and {Facter::Util::Resolution} can be
152
+ # supplied here
153
+ # @option options [Integer] :timeout set the
154
+ # {Facter::Util::Resolution#timeout timeout} for this resolution
155
+ # @param block [Proc] a block defining a fact resolution
156
+ #
157
+ # @return [Facter::Util::Fact] the fact object, which includes any previously
158
+ # defined resolutions
159
+ #
160
+ # @api public
127
161
  def self.add(name, options = {}, &block)
128
162
  collection.add(name, options, &block)
129
163
  end
130
164
 
165
+ # Iterates over fact names and values
166
+ #
167
+ # @yieldparam [String] name the fact name
168
+ # @yieldparam [String] value the current value of the fact
169
+ #
170
+ # @return [void]
171
+ #
172
+ # @api public
131
173
  def self.each
132
174
  # Make sure all facts are loaded.
133
175
  collection.load_all
@@ -137,126 +179,84 @@ module Facter
137
179
  end
138
180
  end
139
181
 
140
- class << self
141
- # Allow users to call fact names directly on the Facter class,
142
- # either retrieving the value or comparing it to an existing value.
143
- def method_missing(name, *args)
144
- question = false
145
- if name.to_s =~ /\?$/
146
- question = true
147
- name = name.to_s.sub(/\?$/,'')
148
- end
149
-
150
- if fact = collection.fact(name)
151
- if question
152
- value = fact.value.downcase
153
- args.each do |arg|
154
- if arg.to_s.downcase == value
155
- return true
156
- end
157
- end
158
-
159
- # If we got this far, there was no match.
160
- return false
161
- else
162
- return fact.value
163
- end
164
- else
165
- # Else, fail like a normal missing method.
166
- raise NoMethodError, "Could not find fact '%s'" % name
167
- end
168
- end
169
- end
170
-
171
- # Clear all facts. Mostly used for testing.
182
+ # Clears all cached values and removes all facts from memory.
183
+ #
184
+ # @return [void]
185
+ #
186
+ # @api public
172
187
  def self.clear
173
188
  Facter.flush
174
189
  Facter.reset
175
190
  end
176
191
 
177
- # Clear all messages. Used only in testing. Can't add to self.clear
178
- # because we don't want to warn multiple times for items that are warnonce'd
179
- def self.clear_messages
180
- @@messages.clear
181
- end
182
-
183
- # Set debugging on or off.
184
- def self.debugging(bit)
185
- if bit
186
- case bit
187
- when TrueClass; @@debug = 1
188
- when FalseClass; @@debug = 0
189
- when Fixnum
190
- if bit > 0
191
- @@debug = 1
192
- else
193
- @@debug = 0
194
- end
195
- when String;
196
- if bit.downcase == 'off'
197
- @@debug = 0
198
- else
199
- @@debug = 1
200
- end
201
- else
202
- @@debug = 0
203
- end
204
- else
205
- @@debug = 0
206
- end
207
- end
208
-
209
- # Set timing on or off.
210
- def self.timing(bit)
211
- if bit
212
- case bit
213
- when TrueClass; @@timing = 1
214
- when Fixnum
215
- if bit > 0
216
- @@timing = 1
217
- else
218
- @@timing = 0
219
- end
220
- end
221
- else
222
- @@timing = 0
223
- end
224
- end
225
-
226
- def self.warn(msg)
227
- if Facter.debugging? and msg and not msg.empty?
228
- msg = [msg] unless msg.respond_to? :each
229
- msg.each { |line| Kernel.warn line }
230
- end
231
- end
232
-
233
- # Warn once.
234
- def self.warnonce(msg)
235
- if msg and not msg.empty? and @@messages[msg].nil?
236
- @@messages[msg] = true
237
- Kernel.warn(msg)
238
- end
239
- end
240
-
241
- # Remove them all.
192
+ # Removes all facts from memory. Use this when the fact code has
193
+ # changed on disk and needs to be reloaded.
194
+ #
195
+ # @return [void]
196
+ #
197
+ # @api public
242
198
  def self.reset
243
199
  @collection = nil
200
+ reset_search_path!
244
201
  end
245
202
 
246
- # Load all of the default facts, and then everything from disk.
203
+ # Loads all facts.
204
+ #
205
+ # @return [void]
206
+ #
207
+ # @api public
247
208
  def self.loadfacts
248
209
  collection.load_all
249
210
  end
250
211
 
251
- @search_path = []
252
-
253
- # Register a directory to search through.
212
+ # Register directories to be searched for facts. The registered directories
213
+ # must be absolute paths or they will be ignored.
214
+ #
215
+ # @param dirs [String] directories to search
216
+ #
217
+ # @return [void]
218
+ #
219
+ # @api public
254
220
  def self.search(*dirs)
255
221
  @search_path += dirs
256
222
  end
257
223
 
258
- # Return our registered search directories.
224
+ # Returns the registered search directories.
225
+ #
226
+ # @return [Array<String>] An array of the directories searched
227
+ #
228
+ # @api public
259
229
  def self.search_path
260
230
  @search_path.dup
261
231
  end
232
+
233
+ # Reset the Facter search directories.
234
+ #
235
+ # @api private
236
+ # @return [void]
237
+ def self.reset_search_path!
238
+ @search_path = []
239
+ end
240
+
241
+ reset_search_path!
242
+
243
+ # Registers directories to be searched for external facts.
244
+ #
245
+ # @param dirs [Array<String>] directories to search
246
+ #
247
+ # @return [void]
248
+ #
249
+ # @api public
250
+ def self.search_external(dirs)
251
+ Facter::Util::Config.external_facts_dirs += dirs
252
+ end
253
+
254
+ # Returns the registered search directories.
255
+ #
256
+ # @return [Array<String>] An array of the directories searched
257
+ #
258
+ # @api public
259
+ def self.search_external_path
260
+ Facter::Util::Config.external_facts_dirs.dup
261
+ end
262
262
  end