Module: PuppetFactset
- Defined in:
- lib/puppet_factset.rb,
lib/puppet_factset/version.rb
Constant Summary collapse
- MERGE_FACTS_DIR =
File.join("spec", "merge_facts")
- VERSION =
"0.4.0"
Class Method Summary collapse
-
.factset_dir ⇒ Object
Return the name of the directory holding the factsets.
-
.factset_hash(factset_name) ⇒ Object
Load factset json file and return a hash.
-
.factsets ⇒ Object
List the available factsets, sorted A-Z.
-
.merge_facts(factset) ⇒ Object
If a directory exists at
merge_factsrelative to the current directory then all JSON files present in this directory will be loaded and merged into passed in factset.
Class Method Details
.factset_dir ⇒ Object
Return the name of the directory holding the factsets
9 10 11 |
# File 'lib/puppet_factset.rb', line 9 def self.factset_dir File.(File.join(File.dirname(__FILE__), '..', 'res', 'factset')) end |
.factset_hash(factset_name) ⇒ Object
Load factset json file and return a hash
14 15 16 17 18 19 20 21 |
# File 'lib/puppet_factset.rb', line 14 def self.factset_hash(factset_name) data = JSON.parse(File.read(File.join(factset_dir(), "#{factset_name}.json"))) merge_facts(data["values"]) # The facts are tucked away inside the 'values' element so just return that data["values"] end |
.factsets ⇒ Object
List the available factsets, sorted A-Z
24 25 26 27 28 |
# File 'lib/puppet_factset.rb', line 24 def self.factsets() Dir.glob(File.join(factset_dir, '*.json')).map { |f| File.basename(f).gsub('.json','') }.sort end |
.merge_facts(factset) ⇒ Object
If a directory exists at merge_facts relative to the current directory then all JSON files present in this directory will be loaded and merged into passed in factset
35 36 37 38 39 40 41 42 |
# File 'lib/puppet_factset.rb', line 35 def self.merge_facts(factset) Dir["#{MERGE_FACTS_DIR}/*.json"].each { |json_file| puts json_file facts = JSON.parse(File.read(json_file)) puts facts factset.merge!(facts) } end |