Class: AbideDevUtils::Ppt::Hiera::Hierarchy

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

Overview

Represents the “hierarchy” section of the Hiera config

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hierarchy, default_datadir) ⇒ Hierarchy

Returns a new instance of Hierarchy.



99
100
101
102
103
104
105
# File 'lib/abide_dev_utils/ppt/hiera.rb', line 99

def initialize(hierarchy, default_datadir)
  @hierarchy = hierarchy
  @default_datadir = File.expand_path(default_datadir)
  @entries = @hierarchy.map { |h| HierarchyEntry.new(h) }
  @by_name_store = {}
  @paths_by_name_store = {}
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args, &block) ⇒ Object



107
108
109
110
111
112
113
# File 'lib/abide_dev_utils/ppt/hiera.rb', line 107

def method_missing(m, *args, &block)
  if %i[each each_with_object each_with_index select reject map].include?(m)
    @entries.send(m, *args, &block)
  else
    super
  end
end

Instance Attribute Details

#default_datadirObject (readonly)

Returns the value of attribute default_datadir.



97
98
99
# File 'lib/abide_dev_utils/ppt/hiera.rb', line 97

def default_datadir
  @default_datadir
end

#entriesObject (readonly)

Returns the value of attribute entries.



97
98
99
# File 'lib/abide_dev_utils/ppt/hiera.rb', line 97

def entries
  @entries
end

Instance Method Details

#entry_by_name(name) ⇒ Object



119
120
121
122
123
124
125
126
127
# File 'lib/abide_dev_utils/ppt/hiera.rb', line 119

def entry_by_name(name)
  AbideDevUtils::Validate.populated_string(name)
  return @by_name_store[name] if @by_name_store[name]

  found = @entries.select { |x| x.name == name }
  AbideDevUtils::Validate.not_empty(found, "Hierarchy entry for name '#{name}' not found")
  @by_name_store[name] = found[0]
  @by_name_store[name]
end

#respond_to_missing?(m, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


115
116
117
# File 'lib/abide_dev_utils/ppt/hiera.rb', line 115

def respond_to_missing?(m, include_private = false)
  %i[each each_with_object each_with_index select reject map].include?(m) || super
end