Module: KOSapiClient::Entity::DataMappings::ClassMethods
- Defined in:
- lib/kosapi_client/entity/data_mappings.rb
Instance Method Summary collapse
- #attr_mappings ⇒ Object
- #map_data(name, type = String, opts = {}) ⇒ Object
-
#parse(content, context = {}) ⇒ BaseEntity
Parses composed domain type from hash response structure.
-
#set_mapped_attributes(instance, source_hash) ⇒ Object
Creates new domain object instance and sets values of mapped domain object attributes from source hash.
Instance Method Details
#attr_mappings ⇒ Object
35 36 37 38 39 40 |
# File 'lib/kosapi_client/entity/data_mappings.rb', line 35 def attr_mappings if self.superclass.respond_to? :attr_mappings parent_mappings = self.superclass.attr_mappings end (parent_mappings || {}).merge(@data_mappings) end |
#map_data(name, type = String, opts = {}) ⇒ Object
28 29 30 31 32 33 |
# File 'lib/kosapi_client/entity/data_mappings.rb', line 28 def map_data(name, type=String, opts = {}) attr_accessor name opts[:type] = type @data_mappings ||= {} @data_mappings[name] = opts end |
#parse(content, context = {}) ⇒ BaseEntity
Parses composed domain type from hash response structure.
46 47 48 49 50 |
# File 'lib/kosapi_client/entity/data_mappings.rb', line 46 def parse(content, context = {}) instance = new() set_mapped_attributes(instance, content) instance end |
#set_mapped_attributes(instance, source_hash) ⇒ Object
Creates new domain object instance and sets values of mapped domain object attributes from source hash. Attributes are mapped by .map_data method.
55 56 57 58 59 60 61 62 63 |
# File 'lib/kosapi_client/entity/data_mappings.rb', line 55 def set_mapped_attributes(instance, source_hash) if self.superclass.respond_to? :set_mapped_attributes self.superclass.set_mapped_attributes(instance, source_hash) end raise "Missing data mappings for entity #{self}" unless @data_mappings @data_mappings.each do |name, | set_mapped_attribute(instance, name, source_hash, ) end end |