Class: LegacyFacter::Util::DirectoryLoader
- Inherits:
-
Object
- Object
- LegacyFacter::Util::DirectoryLoader
- Defined in:
- lib/custom_facts/util/directory_loader.rb
Overview
Defined Under Namespace
Classes: NoSuchDirectoryError
Constant Summary collapse
- EXTERNAL_FACT_WEIGHT =
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
Directory for fact loading.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(dir, weight = nil) ⇒ DirectoryLoader
constructor
A new instance of DirectoryLoader.
-
#load(collection) ⇒ Object
Load facts from files in fact directory using the relevant parser classes to parse them.
Constructor Details
#initialize(dir, weight = nil) ⇒ DirectoryLoader
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)
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
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
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
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 |