Class: LegacyFacter::Util::DirectoryLoader Private
- Inherits:
-
Object
- Object
- LegacyFacter::Util::DirectoryLoader
- Defined in:
- lib/custom_facts/util/directory_loader.rb
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Defined Under Namespace
Classes: NoSuchDirectoryError
Constant Summary collapse
- EXTERNAL_FACT_WEIGHT =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
This value makes it highly likely that external facts will take precedence over all other facts
10_000
Instance Attribute Summary collapse
-
#directory ⇒ Object
readonly
private
Directory for fact loading.
Class Method Summary collapse
- .default_loader ⇒ Object private
- .loader_for(dir) ⇒ Object private
Instance Method Summary collapse
-
#initialize(dir, weight = nil) ⇒ DirectoryLoader
constructor
private
A new instance of DirectoryLoader.
-
#load(collection) ⇒ Object
private
Load facts from files in fact directory using the relevant parser classes to parse them.
Constructor Details
#initialize(dir, weight = nil) ⇒ DirectoryLoader
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of DirectoryLoader.
35 36 37 38 |
# File 'lib/custom_facts/util/directory_loader.rb', line 35 def initialize(dir, weight = nil) @directory = dir @weight = weight || EXTERNAL_FACT_WEIGHT end |
Instance Attribute Details
#directory ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Directory for fact loading
33 34 35 |
# File 'lib/custom_facts/util/directory_loader.rb', line 33 def directory @directory end |
Class Method Details
.default_loader ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
46 47 48 49 50 51 |
# File 'lib/custom_facts/util/directory_loader.rb', line 46 def self.default_loader loaders = LegacyFacter::Util::Config.external_facts_dirs.collect do |dir| LegacyFacter::Util::DirectoryLoader.new(dir) end LegacyFacter::Util::CompositeLoader.new(loaders) end |
.loader_for(dir) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
40 41 42 43 44 |
# File 'lib/custom_facts/util/directory_loader.rb', line 40 def self.loader_for(dir) raise NoSuchDirectoryError unless File.directory?(dir) LegacyFacter::Util::DirectoryLoader.new(dir) end |
Instance Method Details
#load(collection) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Load facts from files in fact directory using the relevant parser classes to parse them.
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/custom_facts/util/directory_loader.rb', line 55 def load(collection) weight = @weight entries.each do |file| parser = LegacyFacter::Util::Parser.parser_for(file) next if parser.nil? data = parser.results if data == false LegacyFacter.warn "Could not interpret fact file #{file}" elsif (data == {}) || data.nil? LegacyFacter.warn "Fact file #{file} was parsed but returned an empty data set" else data.each { |p, v| collection.add(p, value: v) { has_weight(weight) } } end end end |