Module: Cassie::Statements::Statement::Mapping::ClassMethods

Included in:
Assignments, Deleting, Cassie::Statements::Statement::Mapping
Defined in:
lib/cassie/statements/statement/mapping.rb

Instance Method Summary collapse

Instance Method Details

#map_from(resource_name) ⇒ Object

Note:

This delegation behavor gets last preference.

  • An overwritten column_name getter has first preference

  • the @column_name instance variable has next preference

  • the mapped resource delegation has last preference

DSL setting a getter and setter.

When use with a relation (where) or assignment (set), the fetching of column values are delegated to the object in this getter.

Examples:

Simple Mapping delegation

Class Statement
  include Cassie::Statements::Statement:Relations
  include Cassie::Statements::Statement:Mapping

  where :name

  map_from :user
end

s = Statement.new
s.user = User.new(id: 1)
s.id
#=> 1


41
42
43
44
45
46
47
48
49
# File 'lib/cassie/statements/statement/mapping.rb', line 41

def map_from(resource_name)
  define_method resource_name do
    _resource
  end

  define_method "#{resource_name}=" do |val|
    self._resource = val
  end
end