Module: Jirafe::Model
- Included in:
- Callback::Events::Item, Callback::Events::Order, Callback::Events::Refund, Resource::Carts::Item, Resource::JirafeResource, Resource::LegacyResource
- Defined in:
- lib/jirafe/model.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
- #attributes ⇒ Object
- #attributes_for_change(key) ⇒ Object
- #create ⇒ Object
- #initialize(attributes = {}) ⇒ Object
- #reinitialize(attributes = {}) ⇒ Object
- #update ⇒ Object
Class Method Details
.included(base) ⇒ Object
4 5 6 |
# File 'lib/jirafe/model.rb', line 4 def self.included(base) base.extend(ClassMethods) end |
Instance Method Details
#attributes ⇒ Object
63 64 65 66 67 68 |
# File 'lib/jirafe/model.rb', line 63 def attributes self.class.attributes.inject({}) do |hash, attr| hash[attr] = self.send(attr) hash end end |
#attributes_for_change(key) ⇒ Object
70 71 72 73 74 75 76 77 78 |
# File 'lib/jirafe/model.rb', line 70 def attributes_for_change(key) attrs = self.class.attributes.keys.select do |attribute| self.class.attributes[attribute].include?(key) end (attrs || []).inject({}) do |hash, attr| hash[attr] = self.send(attr) hash end end |
#create ⇒ Object
80 81 82 |
# File 'lib/jirafe/model.rb', line 80 def create self.class.create(self) end |
#initialize(attributes = {}) ⇒ Object
52 53 54 |
# File 'lib/jirafe/model.rb', line 52 def initialize(attributes = {}) reinitialize(attributes) end |
#reinitialize(attributes = {}) ⇒ Object
56 57 58 59 60 61 |
# File 'lib/jirafe/model.rb', line 56 def reinitialize(attributes = {}) attributes.each do |attr, value| self.send("#{attr}=", value) if self.respond_to?("#{attr}=") end self end |
#update ⇒ Object
84 85 86 |
# File 'lib/jirafe/model.rb', line 84 def update self.class.update(self) end |