Module: JSONAPI::Serializable::Resource::Relationships::DSL
- Defined in:
- lib/jsonapi/serializable/resource/relationships.rb
Overview
DSL methods for declaring relationships.
Instance Method Summary collapse
- #inherited(klass) ⇒ Object
-
#relationship(name, options = {}, &block) ⇒ Object
(also: #has_many, #has_one, #belongs_to)
Declare a relationship for this resource.
Instance Method Details
#inherited(klass) ⇒ Object
46 47 48 49 |
# File 'lib/jsonapi/serializable/resource/relationships.rb', line 46 def inherited(klass) super klass.relationship_blocks = relationship_blocks.dup end |
#relationship(name, options = {}, &block) ⇒ Object Also known as: has_many, has_one, belongs_to
Declare a relationship for this resource. The properties of the
relationship are set by providing a block in which the DSL methods
of +JSONAPI::Serializable::Relationship+ are called.
81 82 83 84 85 86 87 |
# File 'lib/jsonapi/serializable/resource/relationships.rb', line 81 def relationship(name, = {}, &block) rel_block = proc do data([:class]) { @object.public_send(name) } instance_eval(&block) unless block.nil? end relationship_blocks[name.to_sym] = rel_block end |