Class: AbideDevUtils::Ppt::FacterUtils::FactSets
- Inherits:
-
Object
- Object
- AbideDevUtils::Ppt::FacterUtils::FactSets
- Defined in:
- lib/abide_dev_utils/ppt/facter_utils.rb
Constant Summary collapse
- REQUIRED_FACTERDB_VERSION =
'1.21.0'
Instance Method Summary collapse
- #dot_dig(dot_path, facter_version: latest_version, recurse: true) ⇒ Object (also: #resolve_dot_path)
- #dot_dig_related(*dot_paths, facter_version: latest_version, recurse: true) ⇒ Object (also: #resolve_related_dot_paths)
- #fact_set(facter_version) ⇒ Object
- #fact_sets ⇒ Object
- #facter_versions ⇒ Object
- #find_by_fact_value_tuple(fact_val_tuple) ⇒ Object
- #find_by_fact_value_tuples(*fact_val_tuples) ⇒ Object
-
#initialize ⇒ FactSets
constructor
A new instance of FactSets.
Constructor Details
#initialize ⇒ FactSets
Returns a new instance of FactSets.
60 61 62 63 64 65 |
# File 'lib/abide_dev_utils/ppt/facter_utils.rb', line 60 def initialize check_facterdb_version @fact_val_tuple_cache = {} @dot_dig_cache = {} @dot_dig_related_cache = {} end |
Instance Method Details
#dot_dig(dot_path, facter_version: latest_version, recurse: true) ⇒ Object Also known as: resolve_dot_path
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/abide_dev_utils/ppt/facter_utils.rb', line 107 def dot_dig(dot_path, facter_version: latest_version, recurse: true) ck = cache_key(dot_path, facter_version, recurse) return @dot_dig_cache[ck] if @dot_dig_cache.key?(ck) result = fact_set(facter_version).dot_dig(dot_path) unless result.nil? && recurse @dot_dig_cache[ck] = result return result end previous = previous_version(facter_version) unless previous @dot_dig_cache[ck] = result return result end result = dot_dig(dot_path, facter_version: previous, recurse: true) @dot_dig_cache[ck] = result result end |
#dot_dig_related(*dot_paths, facter_version: latest_version, recurse: true) ⇒ Object Also known as:
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/abide_dev_utils/ppt/facter_utils.rb', line 129 def (*dot_paths, facter_version: latest_version, recurse: true) ck = cache_key(*dot_paths, facter_version, recurse) return @dot_dig_related_cache[ck] if @dot_dig_related_cache.key?(ck) result = [] fact_sets[facter_version].facts.map do |f| result << dot_paths.map { |p| f.dig(*p.delete_prefix('facts').split('.')) } end unless recurse @dot_dig_related_cache[ck] = result.compact.uniq return @dot_dig_related_cache[ck] end previous = previous_version(facter_version) unless previous @dot_dig_related_cache[ck] = result.compact.uniq return @dot_dig_related_cache[ck] end res = result + (*dot_paths, facter_version: previous, recurse: true) @dot_dig_related_cache[ck] = res.compact.uniq @dot_dig_related_cache[ck] end |
#fact_set(facter_version) ⇒ Object
76 77 78 |
# File 'lib/abide_dev_utils/ppt/facter_utils.rb', line 76 def fact_set(facter_version) fact_sets[facter_version] end |
#fact_sets ⇒ Object
67 68 69 70 71 72 73 74 |
# File 'lib/abide_dev_utils/ppt/facter_utils.rb', line 67 def fact_sets @fact_sets ||= FacterDB.facterdb_fact_files.each_with_object({}) do |f, h| facter_version = File.basename(File.dirname(f)) fact_set = h[facter_version] || FactSet.new(facter_version) fact_set.load_facts(f) h[facter_version] = fact_set unless h.key?(facter_version) end end |
#facter_versions ⇒ Object
80 81 82 |
# File 'lib/abide_dev_utils/ppt/facter_utils.rb', line 80 def facter_versions @facter_versions ||= fact_sets.keys.sort end |
#find_by_fact_value_tuple(fact_val_tuple) ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/abide_dev_utils/ppt/facter_utils.rb', line 92 def find_by_fact_value_tuple(fact_val_tuple) ck = cache_key(*fact_val_tuple) return @fact_val_tuple_cache[ck] if @fact_val_tuple_cache.key?(ck) facter_versions.each do |v| result = fact_set(v).find_by_fact_value_tuple(fact_val_tuple) next if result.nil? || result.empty? @fact_val_tuple_cache[ck] = result return result end @fact_val_tuple_cache[ck] = nil end |
#find_by_fact_value_tuples(*fact_val_tuples) ⇒ Object
84 85 86 87 88 89 90 |
# File 'lib/abide_dev_utils/ppt/facter_utils.rb', line 84 def find_by_fact_value_tuples(*fact_val_tuples) fact_sets.each do |_, fs| result = fs.find_by_fact_value_tuples(*fact_val_tuples) return result unless result.nil? || result.empty? end nil end |