Module: Lotus::Entity::ClassMethods
- Defined in:
- lib/lotus/entity.rb
Overview
Instance Method Summary collapse
-
#allowed_attribute_name?(name) ⇒ Boolean
private
Check if attr_reader define the given attribute.
-
#attributes(*attrs) ⇒ Object
(Re)defines getters, setters and initialization for the given attributes.
-
#define_attr_accessor(attr) ⇒ Object
private
Define setter/getter methods for attributes.
Instance Method Details
#allowed_attribute_name?(name) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Check if attr_reader define the given attribute
167 168 169 |
# File 'lib/lotus/entity.rb', line 167 def allowed_attribute_name?(name) !instance_methods.include?(name) end |
#attributes(*attrs) ⇒ 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.
142 143 144 145 146 147 148 149 150 151 |
# File 'lib/lotus/entity.rb', line 142 def attributes(*attrs) return @attributes ||= Set.new unless attrs.any? Lotus::Utils::Kernel.Array(attrs).each do |attr| if allowed_attribute_name?(attr) define_attr_accessor(attr) self.attributes << attr end end end |
#define_attr_accessor(attr) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Define setter/getter methods for attributes.
159 160 161 |
# File 'lib/lotus/entity.rb', line 159 def define_attr_accessor(attr) attr_accessor(attr) end |