Module: AMA::Entity::Mapper::DSL::ClassMethods
- Includes:
- Mixin::Reflection
- Defined in:
- lib/ama-entity-mapper/dsl/class_methods.rb
Overview
Module providing DSL methods for entity class
Instance Method Summary collapse
- #attribute(name, *types, **options) ⇒ AMA::Entity::Mapper::Type::Attribute
- #bound_type ⇒ AMA::Entity::Mapper::Type
- #engine ⇒ Object
- #engine=(engine) ⇒ Object
-
#parameter(id) ⇒ AMA::Entity::Mapper::Type::Parameter
Returns parameter reference.
Methods included from Mixin::Reflection
#install_object_method, #method_object, #object_variable, #object_variable_exists, #object_variables, #set_object_attribute
Methods included from Mixin::Errors
#compliance_error, #mapping_error, #raise_if_internal, #validation_error
Instance Method Details
#attribute(name, *types, **options) ⇒ AMA::Entity::Mapper::Type::Attribute
48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/ama-entity-mapper/dsl/class_methods.rb', line 48 def attribute(name, *types, **) types = types.map(&method(:resolve_type)) types = [Type::Any::INSTANCE] if types.empty? bound_type.attribute!(name, *types, **) define_method(name) do instance_variable_get("@#{name}") end define_method("#{name}=") do |value| instance_variable_set("@#{name}", value) end end |
#bound_type ⇒ AMA::Entity::Mapper::Type
34 35 36 |
# File 'lib/ama-entity-mapper/dsl/class_methods.rb', line 34 def bound_type engine[self] end |
#engine ⇒ Object
28 29 30 31 |
# File 'lib/ama-entity-mapper/dsl/class_methods.rb', line 28 def engine self.engine = Mapper.engine unless @engine @engine end |
#engine=(engine) ⇒ Object
22 23 24 25 26 |
# File 'lib/ama-entity-mapper/dsl/class_methods.rb', line 22 def engine=(engine) @engine = engine engine.register(self) engine end |
#parameter(id) ⇒ AMA::Entity::Mapper::Type::Parameter
Returns parameter reference
64 65 66 |
# File 'lib/ama-entity-mapper/dsl/class_methods.rb', line 64 def parameter(id) bound_type.parameter!(id) end |