Class: Facter::Util::DirectoryLoader
- Inherits:
-
Object
- Object
- Facter::Util::DirectoryLoader
- Defined in:
- lib/facter/util/directory_loader.rb
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
10000
Instance Attribute Summary collapse
-
#directory ⇒ Object
readonly
Directory for fact loading.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(dir) ⇒ 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) ⇒ DirectoryLoader
Returns a new instance of DirectoryLoader.
33 34 35 |
# File 'lib/facter/util/directory_loader.rb', line 33 def initialize(dir) @directory = dir end |
Instance Attribute Details
#directory ⇒ Object (readonly)
Directory for fact loading
31 32 33 |
# File 'lib/facter/util/directory_loader.rb', line 31 def directory @directory end |
Class Method Details
.default_loader ⇒ Object
45 46 47 48 49 50 |
# File 'lib/facter/util/directory_loader.rb', line 45 def self.default_loader loaders = Facter::Util::Config.external_facts_dirs.collect do |dir| Facter::Util::DirectoryLoader.new(dir) end Facter::Util::CompositeLoader.new(loaders) end |
.loader_for(dir) ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/facter/util/directory_loader.rb', line 37 def self.loader_for(dir) if File.directory?(dir) Facter::Util::DirectoryLoader.new(dir) else raise NoSuchDirectoryError end end |
Instance Method Details
#load(collection) ⇒ Object
Load facts from files in fact directory using the relevant parser classes to parse them.
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/facter/util/directory_loader.rb', line 54 def load(collection) entries.each do |file| parser = Facter::Util::Parser.parser_for(file) if parser == nil next end data = parser.results if data == false Facter.warn "Could not interpret fact file #{file}" elsif data == {} or data == nil Facter.warn "Fact file #{file} was parsed but returned an empty data set" else data.each { |p,v| collection.add(p, :value => v) { has_weight(EXTERNAL_FACT_WEIGHT) } } end end end |