Module: DaisybillApi::Ext::Attributes::ClassMethods

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

Instance Method Summary collapse

Instance Method Details

#attribute(name, type, options = {}) ⇒ Object



9
10
11
12
13
14
15
# File 'lib/daisybill_api/ext/attributes.rb', line 9

def attribute(name, type, options = {})
  attrs[name.to_s] = Attribute.new(name, type, options)
  class_eval do
    define_method(name) { read_attribute name }
    define_method(:"#{name}=") { |value| write_attribute name, value }
  end
end

#attributes(attrs) ⇒ Object



17
18
19
20
21
22
# File 'lib/daisybill_api/ext/attributes.rb', line 17

def attributes(attrs)
  options = extract_options(attrs)
  attrs.each { |name, type| attribute(name, type, options) }
  attribute :created_at, :datetime, readonly: true
  attribute :updated_at, :datetime, readonly: true
end

#attrsObject



24
25
26
# File 'lib/daisybill_api/ext/attributes.rb', line 24

def attrs
  @attrs ||= {}
end

#inspectObject



28
29
30
# File 'lib/daisybill_api/ext/attributes.rb', line 28

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