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

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

Parameters:

  • name (String, Symbol)
  • Array<AMA::Entity::Mapper::Type] (Array<AMA::Entity::Mapper::Type] types List of possible attribute types)

    types List of possible attribute types

  • options (Hash)

    Attribute options:

Options Hash (**options):

  • virtual (TrueClass, FalseClass)
  • sensitive (TrueClass, FalseClass)
  • nullable (TrueClass, FalseClass)
  • default (Object)
  • values (Array)

Returns:



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, **options)
  types = types.map(&method(:resolve_type))
  types = [Type::Any::INSTANCE] if types.empty?
  bound_type.attribute!(name, *types, **options)
  define_method(name) do
    instance_variable_get("@#{name}")
  end
  define_method("#{name}=") do |value|
    instance_variable_set("@#{name}", value)
  end
end

#bound_typeAMA::Entity::Mapper::Type



34
35
36
# File 'lib/ama-entity-mapper/dsl/class_methods.rb', line 34

def bound_type
  engine[self]
end

#engineObject



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

Parameters:

  • id (String, Symbol)

Returns:



64
65
66
# File 'lib/ama-entity-mapper/dsl/class_methods.rb', line 64

def parameter(id)
  bound_type.parameter!(id)
end