module Proxima::Attributes

Public Class Methods

included(base) click to toggle source
# File lib/proxima/attributes.rb, line 83
def self.included base
  base.extend ClassMethods
end

Public Instance Methods

<=>(otherModel) click to toggle source
# File lib/proxima/attributes.rb, line 40
def <=> otherModel
  self.id <=> otherModel.id
end
attributes() click to toggle source
# 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 = {}) click to toggle source
# 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) click to toggle source
# File lib/proxima/attributes.rb, line 32
def eql? otherModel
  self.id.eql? otherModel.id
end
hash() click to toggle source
# File lib/proxima/attributes.rb, line 36
def hash
  self.id.hash
end