Class: CemSpecHelper::MappingDataSpec::Mapping
- Inherits:
-
Object
- Object
- CemSpecHelper::MappingDataSpec::Mapping
- Defined in:
- lib/cem_spec_helper/mapping_data_spec.rb
Overview
This class represents a mapping of a framework, OS, and major OS version.
Instance Attribute Summary collapse
-
#framework ⇒ Object
readonly
Returns the value of attribute framework.
-
#majver ⇒ Object
readonly
Returns the value of attribute majver.
-
#module_name ⇒ Object
readonly
Returns the value of attribute module_name.
-
#os ⇒ Object
readonly
Returns the value of attribute os.
Instance Method Summary collapse
-
#add_map(type, map_file) ⇒ Object
Add a map to the mapping.
-
#initialize(framework, os, majver) ⇒ Mapping
constructor
A new instance of Mapping.
-
#map_types ⇒ Array<String>
An array of the map types.
-
#maps ⇒ Array<Hash>
An array of hashes representing the maps.
-
#to_s ⇒ String
A string representation of the mapping.
-
#verify_map_size(keys_with_array_val = find_keys_with_array_val(@maps.dup)) ⇒ TrueClass
Verify that all the mappings have the same size.
-
#verify_one_to_one ⇒ TrueClass
Verify that all mappings are one-to-one, or that there are no duplicate IDs shared between maps.
Constructor Details
#initialize(framework, os, majver) ⇒ Mapping
Returns a new instance of Mapping.
127 128 129 130 131 132 133 |
# File 'lib/cem_spec_helper/mapping_data_spec.rb', line 127 def initialize(framework, os, majver) @framework = framework @os = os @majver = majver @module_name = CemSpecHelper::MODULE_NAME @maps = {} end |
Instance Attribute Details
#framework ⇒ Object (readonly)
Returns the value of attribute framework.
122 123 124 |
# File 'lib/cem_spec_helper/mapping_data_spec.rb', line 122 def framework @framework end |
#majver ⇒ Object (readonly)
Returns the value of attribute majver.
122 123 124 |
# File 'lib/cem_spec_helper/mapping_data_spec.rb', line 122 def majver @majver end |
#module_name ⇒ Object (readonly)
Returns the value of attribute module_name.
122 123 124 |
# File 'lib/cem_spec_helper/mapping_data_spec.rb', line 122 def module_name @module_name end |
#os ⇒ Object (readonly)
Returns the value of attribute os.
122 123 124 |
# File 'lib/cem_spec_helper/mapping_data_spec.rb', line 122 def os @os end |
Instance Method Details
#add_map(type, map_file) ⇒ Object
Add a map to the mapping
143 144 145 |
# File 'lib/cem_spec_helper/mapping_data_spec.rb', line 143 def add_map(type, map_file) @maps[type] = YAML.load_file(map_file) end |
#map_types ⇒ Array<String>
Returns An array of the map types.
148 149 150 |
# File 'lib/cem_spec_helper/mapping_data_spec.rb', line 148 def map_types @maps.keys end |
#maps ⇒ Array<Hash>
Returns An array of hashes representing the maps.
136 137 138 |
# File 'lib/cem_spec_helper/mapping_data_spec.rb', line 136 def maps @maps.values end |
#to_s ⇒ String
Returns A string representation of the mapping.
190 191 192 |
# File 'lib/cem_spec_helper/mapping_data_spec.rb', line 190 def to_s "Mapping[#{framework}, #{os}, #{majver}]" end |
#verify_map_size(keys_with_array_val = find_keys_with_array_val(@maps.dup)) ⇒ TrueClass
Verify that all the mappings have the same size
156 157 158 159 160 161 162 163 164 |
# File 'lib/cem_spec_helper/mapping_data_spec.rb', line 156 def verify_map_size(keys_with_array_val = find_keys_with_array_val(@maps.dup)) result = keys_with_array_val.each_with_object([]) do |(id, map), res| actual_length = 1 + map.length res << id if actual_length != map_types.length end raise "IDs with incorrect map size:\n#{result.join("\n")}" unless result.empty? true end |
#verify_one_to_one ⇒ TrueClass
Verify that all mappings are one-to-one, or that there are no duplicate IDs shared between maps.
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
# File 'lib/cem_spec_helper/mapping_data_spec.rb', line 170 def verify_one_to_one results = @maps.keys.each_with_object([]) do |t, arr| keys_with_array_val = find_keys_with_array_val(@maps[t]) keys_with_array_val.each do |k, v| keys_with_array_val.each do |o_k, o_v| next if o_k == k diff = v - o_v arr << k if diff.length < v.length end end end results.compact! results.uniq! raise "IDs with one-to-many or many-to-many relationships:\n#{results.join("\n")}" unless results.empty? true end |