Module: JSONAPI::Serializable::Relationship::DSL
- Included in:
- JSONAPI::Serializable::Relationship
- Defined in:
- lib/jsonapi/serializable/relationship/dsl.rb
Instance Method Summary collapse
-
#data ⇒ Object
Declare the related resources for this relationship.
-
#link(name, &block) ⇒ Object
Declare a link for this relationship.
- #linkage(always: false, &block) ⇒ Object
- #meta(value = nil) ⇒ Object
Instance Method Details
#data ⇒ Object
Declare the related resources for this relationship. end
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/jsonapi/serializable/relationship/dsl.rb', line 13 def data # NOTE(beauby): Lazify computation since it is only needed when # the corresponding relationship is included. @_resources_block = proc do resources = yield if resources.nil? nil elsif resources.respond_to?(:to_ary) Array(resources).map do |obj| @_class[obj.class.name.to_sym] .new(@_exposures.merge(object: obj)) end else @_class[resources.class.name.to_sym] .new(@_exposures.merge(object: resources)) end end end |
#link(name, &block) ⇒ Object
Declare a link for this relationship. The properties of the link are set
by providing a block in which the DSL methods of
+JSONAPI::Serializable::Link+ are called.
88 89 90 |
# File 'lib/jsonapi/serializable/relationship/dsl.rb', line 88 def link(name, &block) @_links[name] = Link.as_jsonapi(@_exposures, &block) end |
#linkage(options = {}, &block) ⇒ Object #linkage(options = {}) ⇒ Object
46 47 48 49 |
# File 'lib/jsonapi/serializable/relationship/dsl.rb', line 46 def linkage(always: false, &block) @_include_linkage = always @_linkage_block = block end |
#meta(value) ⇒ Object #meta(&block) ⇒ Object
66 67 68 |
# File 'lib/jsonapi/serializable/relationship/dsl.rb', line 66 def (value = nil) = value || yield end |