Class: CemSpecHelper::MappingDataSpec::Mapping
- Inherits:
-
Object
- Object
- CemSpecHelper::MappingDataSpec::Mapping
- Defined in:
- lib/cem_spec_helper/mapping_data_spec.rb
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
-
#initialize(framework, os, majver, module_name: 'cem_linux') ⇒ Mapping
constructor
A new instance of Mapping.
- #map_types ⇒ Object
- #maps ⇒ Object
- #to_s ⇒ Object
- #verify_map_size(keys_with_array_val = find_keys_with_array_val(@maps.dup)) ⇒ Object
- #verify_one_to_one ⇒ Object
Constructor Details
#initialize(framework, os, majver, module_name: 'cem_linux') ⇒ Mapping
Returns a new instance of Mapping.
57 58 59 60 61 62 63 |
# File 'lib/cem_spec_helper/mapping_data_spec.rb', line 57 def initialize(framework, os, majver, module_name: 'cem_linux') @framework = framework @os = os @majver = majver @module_name = module_name @maps = {} end |
Instance Attribute Details
#framework ⇒ Object (readonly)
Returns the value of attribute framework.
55 56 57 |
# File 'lib/cem_spec_helper/mapping_data_spec.rb', line 55 def framework @framework end |
#majver ⇒ Object (readonly)
Returns the value of attribute majver.
55 56 57 |
# File 'lib/cem_spec_helper/mapping_data_spec.rb', line 55 def majver @majver end |
#module_name ⇒ Object (readonly)
Returns the value of attribute module_name.
55 56 57 |
# File 'lib/cem_spec_helper/mapping_data_spec.rb', line 55 def module_name @module_name end |
#os ⇒ Object (readonly)
Returns the value of attribute os.
55 56 57 |
# File 'lib/cem_spec_helper/mapping_data_spec.rb', line 55 def os @os end |
Instance Method Details
#add_map(type, map_file) ⇒ Object
69 70 71 |
# File 'lib/cem_spec_helper/mapping_data_spec.rb', line 69 def add_map(type, map_file) @maps[type] = YAML.load_file(map_file) end |
#map_types ⇒ Object
73 74 75 |
# File 'lib/cem_spec_helper/mapping_data_spec.rb', line 73 def map_types @maps.keys end |
#maps ⇒ Object
65 66 67 |
# File 'lib/cem_spec_helper/mapping_data_spec.rb', line 65 def maps @maps.values end |
#to_s ⇒ Object
106 107 108 |
# File 'lib/cem_spec_helper/mapping_data_spec.rb', line 106 def to_s "Mapping[#{framework}, #{os}, #{majver}]" end |
#verify_map_size(keys_with_array_val = find_keys_with_array_val(@maps.dup)) ⇒ Object
77 78 79 80 81 82 83 84 85 |
# File 'lib/cem_spec_helper/mapping_data_spec.rb', line 77 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 ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/cem_spec_helper/mapping_data_spec.rb', line 87 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 |