Class: AbideDevUtils::Ppt::Hiera::HierarchyEntryPath

Inherits:
Object
  • Object
show all
Defined in:
lib/abide_dev_utils/ppt/hiera.rb

Overview

Represents a Hiera entry path

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#pathObject (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

#factsObject



184
185
186
# File 'lib/abide_dev_utils/ppt/hiera.rb', line 184

def facts
  @facts ||= path.scan(FACT_PATTERN).flatten
end

#facts?Boolean

Returns:

  • (Boolean)


188
189
190
# File 'lib/abide_dev_utils/ppt/hiera.rb', line 188

def facts?
  !facts.empty?
end

#interpolationObject



176
177
178
# File 'lib/abide_dev_utils/ppt/hiera.rb', line 176

def interpolation
  @interpolation ||= path.scan(INTERP_PATTERN).flatten
end

#interpolation?Boolean

Returns:

  • (Boolean)


180
181
182
# File 'lib/abide_dev_utils/ppt/hiera.rb', line 180

def interpolation?
  !interpolation.empty?
end

#local_filesObject



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_partsObject



172
173
174
# File 'lib/abide_dev_utils/ppt/hiera.rb', line 172

def path_parts
  @path_parts ||= path.split('/')
end

#possible_fact_valuesObject



192
193
194
# File 'lib/abide_dev_utils/ppt/hiera.rb', line 192

def possible_fact_values
  @possible_fact_values ||= @fact_sets.resolve_related_dot_paths(*facts)
end

#to_sObject



229
230
231
# File 'lib/abide_dev_utils/ppt/hiera.rb', line 229

def to_s
  path
end