Class: AbideDevUtils::Sce::HieraData::MappingData::MapData

Inherits:
Object
  • Object
show all
Defined in:
lib/abide_dev_utils/sce/hiera_data/mapping_data/map_data.rb

Overview

Represents a single map data file

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ MapData

Returns a new instance of MapData.



9
10
11
# File 'lib/abide_dev_utils/sce/hiera_data/mapping_data/map_data.rb', line 9

def initialize(data)
  @raw_data = data
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



13
14
15
16
17
18
19
# File 'lib/abide_dev_utils/sce/hiera_data/mapping_data/map_data.rb', line 13

def method_missing(meth, *args, &block)
  if data.respond_to?(meth)
    data.send(meth, *args, &block)
  else
    super
  end
end

Instance Method Details

#benchmarkObject



65
66
67
# File 'lib/abide_dev_utils/sce/hiera_data/mapping_data/map_data.rb', line 65

def benchmark
  @raw_data[top_key]['benchmark']
end

#find(identifier, level: nil, profile: nil) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/abide_dev_utils/sce/hiera_data/mapping_data/map_data.rb', line 25

def find(identifier, level: nil, profile: nil)
  levels.each do |lvl|
    next unless level.nil? || lvl != level

    data[lvl].each do |prof, prof_data|
      if prof_data.respond_to?(:keys)
        next unless profile.nil? || prof != profile

        return prof_data[identifier] if prof_data.key?(identifier)
      elsif prof == identifier
        return prof_data
      end
    end
  end
end

#frameworkObject



57
58
59
# File 'lib/abide_dev_utils/sce/hiera_data/mapping_data/map_data.rb', line 57

def framework
  top_key_parts[2]
end

#get(identifier, level: nil, profile: nil) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
# File 'lib/abide_dev_utils/sce/hiera_data/mapping_data/map_data.rb', line 41

def get(identifier, level: nil, profile: nil)
  raise "Invalid level: #{level}" unless profile.nil? || levels.include?(level)
  raise "Invalid profile: #{profile}" unless profile.nil? || profiles.include?(profile)
  return find(identifier, level: level, profile: profile) if level.nil? || profile.nil?

  begin
    data.dig(level, profile, identifier)
  rescue TypeError
    data.dig(level, identifier)
  end
end

#levelsObject



73
74
75
# File 'lib/abide_dev_utils/sce/hiera_data/mapping_data/map_data.rb', line 73

def levels
  levels_and_profiles[0]
end

#levels_and_profilesObject



69
70
71
# File 'lib/abide_dev_utils/sce/hiera_data/mapping_data/map_data.rb', line 69

def levels_and_profiles
  @levels_and_profiles ||= find_levels_and_profiles
end

#module_nameObject



53
54
55
# File 'lib/abide_dev_utils/sce/hiera_data/mapping_data/map_data.rb', line 53

def module_name
  top_key_parts[0]
end

#profilesObject



77
78
79
# File 'lib/abide_dev_utils/sce/hiera_data/mapping_data/map_data.rb', line 77

def profiles
  levels_and_profiles[1]
end

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

Returns:

  • (Boolean)


21
22
23
# File 'lib/abide_dev_utils/sce/hiera_data/mapping_data/map_data.rb', line 21

def respond_to_missing?(meth, include_private = false)
  data.respond_to?(meth) || super
end

#top_keyObject



81
82
83
# File 'lib/abide_dev_utils/sce/hiera_data/mapping_data/map_data.rb', line 81

def top_key
  @top_key ||= @raw_data.keys.first
end

#typeObject



61
62
63
# File 'lib/abide_dev_utils/sce/hiera_data/mapping_data/map_data.rb', line 61

def type
  top_key_parts[3]
end