module DaisybillApi::Ext::Attributes::InstanceMethods

Public Class Methods

new(attributes = {}) click to toggle source
# File lib/daisybill_api/ext/attributes.rb, line 44
def initialize(attributes = {})
  class_attrs.each { |a| attrs[a.name.to_sym] = a.clone }
  self.attributes = attributes
end

Public Instance Methods

attributes() click to toggle source
# File lib/daisybill_api/ext/attributes.rb, line 49
def attributes
  class_attrs.each_with_object({}) { |attr, result|
    result[attr.name] = read_attribute(attr.name)
  }
end
attributes=(attributes) click to toggle source
# File lib/daisybill_api/ext/attributes.rb, line 55
def attributes=(attributes)
  attributes.each { |name, value|
    if attrs[name.to_sym]
      write_attribute name, value
    else
      message = "Was trying to set non-existent attribute #{name.inspect} to #{value.inspect}"
      DaisybillApi.logger.debug message
    end
  }
end
inspect() click to toggle source
# File lib/daisybill_api/ext/attributes.rb, line 72
def inspect
  "<#{self.class.name} #{attributes.map { |k, v| "#{k}: #{v.inspect}" }.join(', ')}>"
end
to_params() click to toggle source
# File lib/daisybill_api/ext/attributes.rb, line 66
def to_params
  attrs.values.each_with_object({}) { |attr, result|
    result.merge! attr.to_param
  }
end

Private Instance Methods

attrs() click to toggle source
# File lib/daisybill_api/ext/attributes.rb, line 90
def attrs
  @attrs ||= {}
end
class_attrs() click to toggle source
# File lib/daisybill_api/ext/attributes.rb, line 86
def class_attrs
  @class_attrs ||= self.class.attrs.values
end
read_attribute(name) click to toggle source
# File lib/daisybill_api/ext/attributes.rb, line 78
def read_attribute(name)
  attrs[name.to_sym].value
end
write_attribute(name, value) click to toggle source
# File lib/daisybill_api/ext/attributes.rb, line 82
def write_attribute(name, value)
  attrs[name.to_sym].value = value
end