Module: PackAPI::Mapping

Defined in:
lib/pack_api/mapping/attribute_map.rb,
lib/pack_api.rb,
lib/pack_api/mapping/filter_map.rb,
lib/pack_api/mapping/null_transformer.rb,
lib/pack_api/mapping/abstract_transformer.rb,
lib/pack_api/mapping/value_object_factory.rb,
lib/pack_api/mapping/attribute_map_registry.rb,
lib/pack_api/mapping/normalized_api_attribute.rb,
lib/pack_api/mapping/attribute_hash_transformer.rb,
lib/pack_api/mapping/api_to_model_attributes_transformer.rb,
lib/pack_api/mapping/model_to_api_attributes_transformer.rb,
lib/pack_api/mapping/error_hash_to_api_attributes_transformer.rb

Overview

Map (convert) the names of attributes presented on one side of an API to those required on the other side. Handles 3 scenarios:

1. create/update API endpoints
  IN: attribute Hash with names conforming to the ValueObject type attributes*
  OUT: attribute Hash with names conforming to the ActiveRecord model type

  * generally true; except when it's not. For example, if the ValueObject type has an attribute
    named "user", and the ActiveRecord model has an attribute named "user", typically this is set during
    create/update calls by passing in the "user_id" attribute.
  1. converting an ActiveRecord model as a ValueObject IN: ActiveRecord model instance OUT: attribute Hash with names conforming to the ValueObject type attributes

  2. converting an ActiveModel::Errors instance to an attribute Hash IN: ActiveModel::Errors instance OUT: attribute Hash with names conforming to the ValueObject type attributes*

    • generally true; except when it's not. For example, if the ValueObject type has an attribute named "user", and the ActiveRecord model has an attribute named "user", typically this is set during create/update calls by passing in the "user_id" attribute. Therefore, the error hash will have to associate the error with the "user_id" attribute (not the "user" attribute).

Defined Under Namespace

Classes: APIToModelAttributesTransformer, AbstractTransformer, AttributeHashTransformer, AttributeMap, AttributeMapRegistry, ErrorHashToAPIAttributesTransformer, FilterMap, ModelToAPIAttributesTransformer, NormalizedAPIAttribute, NullTransformer, ValueObjectFactory