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. By default, the values will be whatever the value of the Hash at that key is.
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(attrs = {}) ⇒ Object
Creates your object.
Class Method Details
.included(base) ⇒ Object
24 25 26 |
# File 'lib/objectmancy/objectable.rb', line 24 def self.included(base) base.extend(ClassMethods) end |
Instance Method Details
#initialize(attrs = {}) ⇒ Object
Creates your object. You should use the after_initialize
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/objectmancy/objectable.rb', line 94 def initialize(attrs = {}) before_initialize _assignable_attributes(attrs).each do |attr, value| = self.class.registered_attributes[attr.to_sym] value = if .multiple _convert_multiples(value, .type, .objectable) else _single_value(value, ) end send("#{attr}=", value) end after_initialize end |