Class: AbideDevUtils::Ppt::Hiera::HierarchyEntryPath
- Inherits:
-
Object
- Object
- AbideDevUtils::Ppt::Hiera::HierarchyEntryPath
- Defined in:
- lib/abide_dev_utils/ppt/hiera.rb
Overview
Represents a Hiera entry path
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #facts ⇒ Object
- #facts? ⇒ Boolean
-
#initialize(path) ⇒ HierarchyEntryPath
constructor
A new instance of HierarchyEntryPath.
- #interpolation ⇒ Object
- #interpolation? ⇒ Boolean
- #local_files ⇒ Object
- #local_files_with_fact(fact_str, value = nil) ⇒ Object
- #local_files_with_facts(*fact_arrays) ⇒ Object
- #path_parts ⇒ Object
- #possible_fact_values ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(path) ⇒ HierarchyEntryPath
Returns a new instance of HierarchyEntryPath.
167 168 169 170 |
# File 'lib/abide_dev_utils/ppt/hiera.rb', line 167 def initialize(path) @path = path @fact_sets = AbideDevUtils::Ppt::FacterUtils::FactSets.new end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
165 166 167 |
# File 'lib/abide_dev_utils/ppt/hiera.rb', line 165 def path @path end |
Instance Method Details
#facts ⇒ Object
184 185 186 |
# File 'lib/abide_dev_utils/ppt/hiera.rb', line 184 def facts @facts ||= path.scan(FACT_PATTERN).flatten end |
#facts? ⇒ Boolean
188 189 190 |
# File 'lib/abide_dev_utils/ppt/hiera.rb', line 188 def facts? !facts.empty? end |
#interpolation ⇒ Object
176 177 178 |
# File 'lib/abide_dev_utils/ppt/hiera.rb', line 176 def interpolation @interpolation ||= path.scan(INTERP_PATTERN).flatten end |
#interpolation? ⇒ Boolean
180 181 182 |
# File 'lib/abide_dev_utils/ppt/hiera.rb', line 180 def interpolation? !interpolation.empty? end |
#local_files ⇒ Object
196 197 198 |
# File 'lib/abide_dev_utils/ppt/hiera.rb', line 196 def local_files @local_files ||= find_local_files.flatten end |
#local_files_with_fact(fact_str, value = nil) ⇒ Object
200 201 202 203 204 205 |
# File 'lib/abide_dev_utils/ppt/hiera.rb', line 200 def local_files_with_fact(fact_str, value = nil) local_files.select do |lf| # The match below is case-insentive for convenience (value.nil? ? lf.fact_values.key?(fact_str) : (lf.fact_values[fact_str]&.match?(/#{value}/i) || false)) end end |
#local_files_with_facts(*fact_arrays) ⇒ Object
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 |
# File 'lib/abide_dev_utils/ppt/hiera.rb', line 207 def local_files_with_facts(*fact_arrays) return local_files_with_fact(*fact_arrays[0]) if fact_arrays.length == 1 start_fact = fact_arrays[0][0] last_fact = nil memo = {} with_facts = [] fact_arrays.each do |fa| cur_fact = fa[0] memo[cur_fact] = local_files_with_fact(*fa) if cur_fact == start_fact with_facts = memo[cur_fact] else last_paths = memo[last_fact].map(&:path) cur_paths = memo[cur_fact].map(&:path) with_facts.reject! { |x| last_paths.difference(cur_paths).include?(x.path) } end last_fact = cur_fact end with_facts.flatten.uniq(&:path) end |
#path_parts ⇒ Object
172 173 174 |
# File 'lib/abide_dev_utils/ppt/hiera.rb', line 172 def path_parts @path_parts ||= path.split('/') end |
#possible_fact_values ⇒ Object
192 193 194 |
# File 'lib/abide_dev_utils/ppt/hiera.rb', line 192 def possible_fact_values @possible_fact_values ||= @fact_sets.(*facts) end |
#to_s ⇒ Object
229 230 231 |
# File 'lib/abide_dev_utils/ppt/hiera.rb', line 229 def to_s path end |