module DaisybillApi::Ext::Attributes::ClassMethods
Constants
- OPTION_KEYS
Public Instance Methods
attribute(name, type, options = {})
click to toggle source
# 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)
click to toggle source
# 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
attrs()
click to toggle source
# File lib/daisybill_api/ext/attributes.rb, line 24 def attrs @attrs ||= {} end
inspect()
click to toggle source
# File lib/daisybill_api/ext/attributes.rb, line 28 def inspect "<#{name} #{attrs.map{ |k, v| "#{k}: #{v.type}"}.join(', ')}>" end
Private Instance Methods
extract_options(attributes)
click to toggle source
# File lib/daisybill_api/ext/attributes.rb, line 36 def extract_options(attributes) OPTION_KEYS.each_with_object({}) { |key, result| result[key] = attributes.delete key } end