Class: AbideDevUtils::Sce::Mapping::Mapper

Inherits:
Object
  • Object
show all
Defined in:
lib/abide_dev_utils/sce/mapping/mapper.rb

Overview

Handles interacting with mapping data

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(module_name, framework, map_data) ⇒ Mapper

Returns a new instance of Mapper.



122
123
124
125
126
127
128
129
# File 'lib/abide_dev_utils/sce/mapping/mapper.rb', line 122

def initialize(module_name, framework, map_data)
  @module_name = module_name
  @framework = framework
  load_framework(@framework)
  @map_data = map_data.map { |_, v| MapData.new(v) }
  @cache = {}
  @rule_cache = {}
end

Instance Attribute Details

#frameworkObject (readonly)

Returns the value of attribute framework.



120
121
122
# File 'lib/abide_dev_utils/sce/mapping/mapper.rb', line 120

def framework
  @framework
end

#map_dataObject (readonly)

Returns the value of attribute map_data.



120
121
122
# File 'lib/abide_dev_utils/sce/mapping/mapper.rb', line 120

def map_data
  @map_data
end

#module_nameObject (readonly)

Returns the value of attribute module_name.



120
121
122
# File 'lib/abide_dev_utils/sce/mapping/mapper.rb', line 120

def module_name
  @module_name
end

Instance Method Details

#each_like(identifier) ⇒ Object



147
148
149
# File 'lib/abide_dev_utils/sce/mapping/mapper.rb', line 147

def each_like(identifier)
  identified_map_data(identifier)&.each { |key, val| yield key, val }
end

#each_with_array_like(identifier) ⇒ Object



151
152
153
# File 'lib/abide_dev_utils/sce/mapping/mapper.rb', line 151

def each_with_array_like(identifier)
  identified_map_data(identifier)&.each_with_object([]) { |(key, val), ary| yield [key, val], ary }
end

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



155
156
157
# File 'lib/abide_dev_utils/sce/mapping/mapper.rb', line 155

def get(control_id, level: nil, profile: nil)
  identified_map_data(control_id)&.get(control_id, level: level, profile: profile)
end

#levelsObject



139
140
141
# File 'lib/abide_dev_utils/sce/mapping/mapper.rb', line 139

def levels
  @levels ||= default_map_data.levels
end

#map_type(control_id) ⇒ Object



159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# File 'lib/abide_dev_utils/sce/mapping/mapper.rb', line 159

def map_type(control_id)
  return control_id if ALL_TYPES.include?(control_id)

  case control_id
  when %r{^c[0-9_]+$}
    'hiera_title_num'
  when %r{^[0-9][0-9.]*$}
    'number'
  when %r{^[a-z][a-z0-9_]+$}
    'hiera_title'
  when %r{^V-[0-9]{6}$}
    'vulnid'
  when %r{^SV-[0-9]+r[0-9]+_rule$}
    'ruleid'
  else
    'title'
  end
end

#profilesObject



143
144
145
# File 'lib/abide_dev_utils/sce/mapping/mapper.rb', line 143

def profiles
  @profiles ||= default_map_data.profiles
end

#titleObject



131
132
133
# File 'lib/abide_dev_utils/sce/mapping/mapper.rb', line 131

def title
  @title ||= benchmark_data['title']
end

#versionObject



135
136
137
# File 'lib/abide_dev_utils/sce/mapping/mapper.rb', line 135

def version
  @version ||= benchmark_data['version']
end