Module: DaisybillApi::Ext::Attributes::ClassMethods
- Defined in:
- lib/daisybill_api/ext/attributes.rb
Instance Method Summary collapse
- #attribute(name, type, options = {}) ⇒ Object
- #attributes(attrs) ⇒ Object
- #attrs ⇒ Object
- #inspect ⇒ Object
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, = {}) attrs[name.to_s] = Attribute.new(name, type, ) 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) = (attrs) attrs.each { |name, type| attribute(name, type, ) } attribute :created_at, :datetime, readonly: true attribute :updated_at, :datetime, readonly: true end |
#attrs ⇒ Object
24 25 26 |
# File 'lib/daisybill_api/ext/attributes.rb', line 24 def attrs @attrs ||= {} end |
#inspect ⇒ Object
28 29 30 |
# File 'lib/daisybill_api/ext/attributes.rb', line 28 def inspect "<#{name} #{attrs.map{ |k, v| "#{k}: #{v.type}"}.join(', ')}>" end |