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 |
# File 'lib/abide_dev_utils/ppt/hiera.rb', line 167 def initialize(path) @path = path 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
183 184 185 |
# File 'lib/abide_dev_utils/ppt/hiera.rb', line 183 def facts @facts ||= path.scan(FACT_PATTERN).flatten end |
#facts? ⇒ Boolean
187 188 189 |
# File 'lib/abide_dev_utils/ppt/hiera.rb', line 187 def facts? !facts.empty? end |
#interpolation ⇒ Object
175 176 177 |
# File 'lib/abide_dev_utils/ppt/hiera.rb', line 175 def interpolation @interpolation ||= path.scan(INTERP_PATTERN).flatten end |
#interpolation? ⇒ Boolean
179 180 181 |
# File 'lib/abide_dev_utils/ppt/hiera.rb', line 179 def interpolation? !interpolation.empty? end |
#local_files ⇒ Object
195 196 197 |
# File 'lib/abide_dev_utils/ppt/hiera.rb', line 195 def local_files @local_files ||= find_local_files.flatten end |
#local_files_with_fact(fact_str, value = nil) ⇒ Object
199 200 201 202 203 204 |
# File 'lib/abide_dev_utils/ppt/hiera.rb', line 199 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
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 |
# File 'lib/abide_dev_utils/ppt/hiera.rb', line 206 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
171 172 173 |
# File 'lib/abide_dev_utils/ppt/hiera.rb', line 171 def path_parts @path_parts ||= path.split('/') end |
#possible_fact_values ⇒ Object
191 192 193 |
# File 'lib/abide_dev_utils/ppt/hiera.rb', line 191 def possible_fact_values @possible_fact_values ||= AbideDevUtils::Ppt::FacterUtils.(*facts) end |
#to_s ⇒ Object
228 229 230 |
# File 'lib/abide_dev_utils/ppt/hiera.rb', line 228 def to_s path end |