Module: Jirafe::Model

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

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

#attributesObject



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

#createObject



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

#updateObject



84
85
86
# File 'lib/jirafe/model.rb', line 84

def update
  self.class.update(self)
end