Module: Epiphy::Entity::ClassMethods
- Defined in:
- lib/epiphy/entity.rb
Overview
Instance Method Summary collapse
- #attributes ⇒ Object
-
#attributes=(*attributes) ⇒ Object
(Re)defines getters, setters and initialization for the given attributes.
Instance Method Details
#attributes ⇒ Object
117 118 119 |
# File 'lib/epiphy/entity.rb', line 117 def attributes @attributes end |
#attributes=(*attributes) ⇒ Object
(Re)defines getters, setters and initialization for the given attributes.
These attributes can match the database columns, but this isn’t a requirement. The mapper used by the relative repository will translate these names automatically.
An entity can work with attributes not configured in the mapper, but of course they will be ignored when the entity will be persisted.
Please notice that the required ‘id` attribute is automatically defined and can be omitted in the arguments.
105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/epiphy/entity.rb', line 105 def attributes=(*attributes) @attributes = Lotus::Utils::Kernel.Array(attributes.unshift(:id)) class_eval %{ def initialize(attributes = {}) #{ @attributes.map {|a| "@#{a}" }.join(', ') }, = *attributes.values_at(#{ @attributes.map {|a| ":#{a}"}.join(', ') }) end } attr_accessor *@attributes end |