Module: JSONAPI::Serializable::Resource::Attributes::DSL
- Defined in:
- lib/jsonapi/serializable/resource/attributes.rb
Overview
DSL methods for declaring attributes.
Instance Method Summary collapse
-
#attribute(name, _options = {}, &block) ⇒ Object
Declare an attribute for this resource.
-
#attributes(*args) ⇒ Object
Declare a list of attributes for this resource.
- #inherited(klass) ⇒ Object
Instance Method Details
#attribute(name, _options = {}, &block) ⇒ Object
Declare an attribute for this resource.
53 54 55 56 |
# File 'lib/jsonapi/serializable/resource/attributes.rb', line 53 def attribute(name, = {}, &block) block ||= proc { @object.public_send(name) } attribute_blocks[name.to_sym] = block end |
#attributes(*args) ⇒ Object
Declare a list of attributes for this resource.
64 65 66 67 68 |
# File 'lib/jsonapi/serializable/resource/attributes.rb', line 64 def attributes(*args) args.each do |attr| attribute(attr) end end |
#inherited(klass) ⇒ Object
41 42 43 44 |
# File 'lib/jsonapi/serializable/resource/attributes.rb', line 41 def inherited(klass) super klass.attribute_blocks = attribute_blocks.dup end |