Module: Cylons::Attributes
Instance Method Summary collapse
- #read_attribute(name) ⇒ Object (also: #[])
-
#write_attribute(name, value) ⇒ Object
(also: #[]=, #attribute=)
Override #write_attribute (along with #[]=) so we can provide support for ActiveModel::Dirty.
Instance Method Details
#read_attribute(name) ⇒ Object Also known as: []
3 4 5 6 7 8 9 10 11 |
# File 'lib/cylons/attributes.rb', line 3 def read_attribute(name) name = name.to_s if @attributes.has_key?(name) || self.respond_to?(name) @attributes[name] else raise ::ActiveAttr::UnknownAttributeError, "unknown attribute: #{name}" end end |
#write_attribute(name, value) ⇒ Object Also known as: []=, attribute=
Override #write_attribute (along with #[]=) so we can provide support for ActiveModel::Dirty.
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/cylons/attributes.rb', line 17 def write_attribute(name, value) __send__("#{name}_will_change!") if value != self[name] name = name.to_s if @attributes.has_key?(name) || self.respond_to?(name) @attributes[name] = value else raise ::ActiveAttr::UnknownAttributeError, "unknown attribute: #{name}" end end |