module Datamappify::Entity::Relation::DSL
Public Instance Methods
references(entity_name)
click to toggle source
@param entity_name [Symbol, String]
@return [void]
# 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
Private Instance Methods
create_accessor(entity_name)
click to toggle source
@param entity_name (see references
)
@return [void]
# File lib/datamappify/entity/relation.rb, line 30 def create_accessor(entity_name) class_eval <<-CODE, __FILE__, __LINE__ + 1 attr_reader :#{entity_name} def #{entity_name}=(entity) @#{entity_name} = entity self.#{entity_name}_id = entity.nil? ? nil : entity.id end CODE end
create_attribute(name, type, *args)
click to toggle source
@param name [Symbol]
@param type [Class]
@param options [any]
@return [void]
# File lib/datamappify/entity/relation.rb, line 48 def create_attribute(name, type, *args) attribute name, type, *args end
record_attribute(attribute_name)
click to toggle source
@param attribute_name [Symbol]
@return [Array]
# File lib/datamappify/entity/relation.rb, line 55 def record_attribute(attribute_name) self.reference_keys << attribute_name end