Module: ShafClient::ResourceMapper
- Defined in:
- lib/shaf_client/resource_mapper.rb
Class Method Summary collapse
- .default=(clazz) ⇒ Object
- .for(content_type:, headers: {}, payload: nil, client: nil) ⇒ Object
- .register(content_type, profile = nil, clazz) ⇒ Object
- .unregister(content_type, profile = nil) ⇒ Object
Class Method Details
.default=(clazz) ⇒ Object
26 27 28 |
# File 'lib/shaf_client/resource_mapper.rb', line 26 def default=(clazz) mapping.default = clazz end |
.for(content_type:, headers: {}, payload: nil, client: nil) ⇒ Object
8 9 10 11 12 13 14 15 16 |
# File 'lib/shaf_client/resource_mapper.rb', line 8 def for(content_type:, headers: {}, payload: nil, client: nil) content_type = content_type&.to_sym profile = profile_from(content_type, headers, payload) clazz, extensions = result_for(content_type, payload, profile, client) raise_unsupported_error(content_type) unless clazz [clazz, extensions] end |
.register(content_type, profile = nil, clazz) ⇒ Object
18 19 20 |
# File 'lib/shaf_client/resource_mapper.rb', line 18 def register(content_type, profile = nil, clazz) mapping[content_type&.to_sym, profile] = clazz end |
.unregister(content_type, profile = nil) ⇒ Object
22 23 24 |
# File 'lib/shaf_client/resource_mapper.rb', line 22 def unregister(content_type, profile = nil) mapping.delete(content_type.to_sym, profile) end |