Module: Entasis::Model
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
-
#attributes ⇒ Object
Returns all attributes serialized as hash.
-
#attributes=(hash) ⇒ Object
Takes a hash of attribute names and values and set each attribute.
-
#initialize(hash = {}) ⇒ Object
Takes a hash and assigns keys and values to it’s attributes members.
Instance Method Details
#attributes ⇒ Object
Returns all attributes serialized as hash
63 64 65 |
# File 'lib/entasis/model.rb', line 63 def attributes attribute_names.inject({}) { |h, name| h[name] = send(name); h } end |
#attributes=(hash) ⇒ Object
Takes a hash of attribute names and values and set each attribute.
If passwed an unkown attribute it will raise class::UnknownAttributeError
47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/entasis/model.rb', line 47 def attributes=(hash) hash.each do |name, value| if attribute_names.include?(name.to_s) || self.respond_to?("#{name}=") self.send("#{name}=", value) else if attributes_config[:strict] == true raise self.class::UnknownAttributeError, "unknown attribute: #{name}" end end end end |
#initialize(hash = {}) ⇒ Object
Takes a hash and assigns keys and values to it’s attributes members
37 38 39 |
# File 'lib/entasis/model.rb', line 37 def initialize(hash={}) self.attributes = hash end |