Module: Proxima::Attributes

Included in:
Model
Defined in:
lib/proxima/attributes.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



83
84
85
# File 'lib/proxima/attributes.rb', line 83

def self.included base
  base.extend ClassMethods
end

Instance Method Details

#<=>(otherModel) ⇒ Object



40
41
42
# File 'lib/proxima/attributes.rb', line 40

def <=> otherModel
  self.id <=> otherModel.id
end

#attributesObject



6
7
8
9
10
11
12
13
# File 'lib/proxima/attributes.rb', line 6

def attributes
  attributes_hash = {}
  self.class.attributes.each do |attribute, params|
    value = self.send attribute
    attributes_hash[attribute.to_s] = value
  end
  attributes_hash
end

#attributes=(params = {}) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/proxima/attributes.rb', line 15

def attributes=(params = {})
  self.class.attributes.each do |attribute, attribute_params|
    value = params[attribute]

    if value == nil && default = attribute_params[:default]
      value = default.respond_to?(:call) ? default.call(self, params) : default
    end

    if value != nil && attribute_params[:klass] && !value.is_a?(attribute_params[:klass])
      klass = attribute_params[:klass]
      value = Proxima::type_from_json klass, value
    end

    self.send "#{attribute}=", value
  end
end

#eql?(otherModel) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/proxima/attributes.rb', line 32

def eql? otherModel
  self.id.eql? otherModel.id
end

#hashObject



36
37
38
# File 'lib/proxima/attributes.rb', line 36

def hash
  self.id.hash
end