Skip to content

Commit

Permalink
Minimal workaround for issue #7.
Browse files Browse the repository at this point in the history
Attributes that the server sends, but the local API definition is
not aware of will be ignored. This should allow for some forward
compatibility as long as the new attributes are not required.

This issue stems from the design goal of minimizing dependencies
which eliminated the option of parsing the WSDL at runtime.

This is not an ideal solution - realistically, I would recommend
the M&M provided REST API now that it is available.
  • Loading branch information
Eric Wannemacher committed Jan 13, 2020
1 parent fcd93e4 commit f36a8be
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/mm_json_client/type_factory.rb
Expand Up @@ -50,7 +50,9 @@ def build_complex_type(type_name, data)
type_def = type_definition(type_name)
data.each do |attr_name, value|
subtype = type_def[attr_name]
obj.send("#{attr_name}=", build_from_data(subtype, value))
if subtype then # ignore any types that we do not have in the definition
obj.send("#{attr_name}=", build_from_data(subtype, value))
end
end
end
end
Expand Down
14 changes: 14 additions & 0 deletions spec/lib/mm_json_client/type_factory_spec.rb
Expand Up @@ -84,5 +84,19 @@
planet_names = subject.favorite_planets.map(&:name).sort
expect(planet_names).to eq(%w(earth mars))
end

it 'ignores attributes not in the API spec' do
type_factory.load_types('TestType' => { 'name' => 'string',
'home_planet' => 'string' })

subject =
type_factory.build_from_data('TestType', 'name' => 'The Tick',
'home_planet' => 'Earth',
'weakness' => 'shiny objects')

expect(subject.name).to eq('The Tick')
expect(subject.home_planet).to eq('Earth')
expect{subject.weakness}.to raise_error(NoMethodError)
end
end
end

0 comments on commit f36a8be

Please sign in to comment.