Module: Kangaroo::Attributes
- Included in:
- Model::Base, Model::Field
- Defined in:
- lib/kangaroo/model/attributes.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
-
#attributes ⇒ Hash
Read all attributes.
-
#attributes=(attributes) ⇒ Hash
Mass set attributes.
-
#freeze ⇒ Object
Freeze this object.
-
#read_attribute(name) ⇒ Object
Read an attribute value by name.
-
#write_attribute(name, value) ⇒ Object
Write an attribute by name.
Instance Method Details
#attributes ⇒ Hash
Read all attributes. Attributes are read via getters.
45 46 47 48 49 50 51 |
# File 'lib/kangaroo/model/attributes.rb', line 45 def attributes {}.tap do |attributes| self.class.attribute_names.each do |key| attributes[key] = send(key) end end end |
#attributes=(attributes) ⇒ Hash
Mass set attributes. Attribute values are set via setters, not directly stored in the @attributes Hash.
34 35 36 37 38 39 40 |
# File 'lib/kangaroo/model/attributes.rb', line 34 def attributes= attributes attributes.except('id', :id).map do |key_value| __send__ "#{key_value.first}=", key_value.last end self.attributes end |
#freeze ⇒ Object
Freeze this object
54 55 56 57 58 |
# File 'lib/kangaroo/model/attributes.rb', line 54 def freeze @changed_attributes.freeze @attributes.freeze super end |
#read_attribute(name) ⇒ Object
Read an attribute value by name
15 16 17 |
# File 'lib/kangaroo/model/attributes.rb', line 15 def read_attribute name @attributes[name.to_s] end |
#write_attribute(name, value) ⇒ Object
Write an attribute by name
24 25 26 27 |
# File 'lib/kangaroo/model/attributes.rb', line 24 def write_attribute name, value attribute_will_change! name.to_s @attributes[name.to_s] = value end |