Module: DaisybillApi::Ext::Attributes::InstanceMethods

Defined in:
lib/daisybill_api/ext/attributes.rb

Instance Method Summary collapse

Instance Method Details

#attributesObject



49
50
51
52
53
# 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) ⇒ Object



55
56
57
58
59
60
61
62
63
64
# 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

#initialize(attributes = {}) ⇒ Object



44
45
46
47
# 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

#inspectObject



72
73
74
# File 'lib/daisybill_api/ext/attributes.rb', line 72

def inspect
  "<#{self.class.name} #{attributes.map { |k, v| "#{k}: #{v.inspect}" }.join(', ')}>"
end

#to_paramsObject



66
67
68
69
70
# 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