Module: Datamappify::Entity::Relation::DSL

Defined in:
lib/datamappify/entity/relation.rb

Instance Method Summary collapse

Instance Method Details

#create_accessor(entity_name) ⇒ void (private)



30
31
32
33
34
35
36
37
38
39
# File 'lib/datamappify/entity/relation.rb', line 30

def create_accessor(entity_name)
  class_eval "    attr_reader :\#{entity_name}\n\n    def \#{entity_name}=(entity)\n      @\#{entity_name}        = entity\n      self.\#{entity_name}_id = entity.nil? ? nil : entity.id\n    end\n  CODE\nend\n", __FILE__, __LINE__ + 1

#create_attribute(name, type, *args) ⇒ void (private)



48
49
50
# File 'lib/datamappify/entity/relation.rb', line 48

def create_attribute(name, type, *args)
  attribute name, type, *args
end

#record_attribute(attribute_name) ⇒ Array (private)



55
56
57
# File 'lib/datamappify/entity/relation.rb', line 55

def record_attribute(attribute_name)
  self.reference_keys << attribute_name
end

#references(entity_name) ⇒ void



17
18
19
20
21
22
23
# File 'lib/datamappify/entity/relation.rb', line 17

def references(entity_name)
  attribute_name = :"#{entity_name}_id"

  create_attribute attribute_name, Integer
  create_accessor entity_name
  record_attribute attribute_name
end