Module: JSONAPI::Serializable::Resource::KeyFormat::DSL
- Defined in:
- lib/jsonapi/serializable/resource/key_format.rb
Overview
DSL extensions for automatic key transformations.
Instance Method Summary collapse
-
#attribute(name, options = {}, &block) ⇒ Object
Handles automatic key transformation for attributes.
- #inherited(klass) ⇒ Object
-
#relationship(name, options = {}, &block) ⇒ Object
Handles automatic key transformation for relationships.
Instance Method Details
#attribute(name, options = {}, &block) ⇒ Object
Handles automatic key transformation for attributes.
34 35 36 37 |
# File 'lib/jsonapi/serializable/resource/key_format.rb', line 34 def attribute(name, = {}, &block) block ||= proc { @object.public_send(name) } super(key_format.call(name), , &block) end |
#inherited(klass) ⇒ Object
28 29 30 31 |
# File 'lib/jsonapi/serializable/resource/key_format.rb', line 28 def inherited(klass) super klass.key_format = key_format end |
#relationship(name, options = {}, &block) ⇒ Object
Handles automatic key transformation for relationships.
40 41 42 43 44 45 46 |
# File 'lib/jsonapi/serializable/resource/key_format.rb', line 40 def relationship(name, = {}, &block) rel_block = proc do data([:class]) { @object.public_send(name) } instance_eval(&block) unless block.nil? end super(key_format.call(name), , &rel_block) end |