Module: Objectmancy::Objectable
- Defined in:
- lib/objectmancy/objectable.rb
Overview
Mixin for allowing your objects to take a Hash and turn them into an object.
Class Method Summary collapse
Instance Method Summary collapse
-
#==(other) ⇒ TrueClass, FalseClass
Comparator for two objects.
-
#initialize(attrs = {}) ⇒ Object
Creates your object.
-
#mass_update(attrs = {}) ⇒ Object
Updates the attributes of the object.
Class Method Details
.included(base) ⇒ Object
18 19 20 |
# File 'lib/objectmancy/objectable.rb', line 18 def self.included(base) base.extend(CommonClassMethods) end |
Instance Method Details
#==(other) ⇒ TrueClass, FalseClass
Comparator for two objects
45 46 47 48 49 50 |
# File 'lib/objectmancy/objectable.rb', line 45 def ==(other) self.class == other.class && self.class.registered_attributes.keys.all? do |attr| send(attr) == other.send(attr) end end |
#initialize(attrs = {}) ⇒ Object
Creates your object. You should use the after_initialize
25 26 27 28 29 30 31 |
# File 'lib/objectmancy/objectable.rb', line 25 def initialize(attrs = {}) before_initialize _attributes_update!(attrs) after_initialize end |
#mass_update(attrs = {}) ⇒ Object
Updates the attributes of the object
36 37 38 |
# File 'lib/objectmancy/objectable.rb', line 36 def mass_update(attrs = {}) _attributes_update!(attrs) end |