module JSONAPI::Serializable::Relationship::DSL
Public Instance Methods
data() { || ... }
click to toggle source
Declare the related resources for this relationship. @yieldreturn The related resources for this relationship.
@example
data do @object.posts end
end
# 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 JSONAPI::Serializable.resources_for(yield, @_exposures, @_class) end end
link(name, &block)
click to toggle source
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.
@see JSONAPI::Serialiable::Link
@param [Symbol] name The key of the link. @yieldreturn [Hash, String, nil] The block to compute the value, if any.
@example
link(:self) do "http://api.example.com/users/#{@user.id}/relationships/posts" end
@example
link(:related) do href "http://api.example.com/users/#{@user.id}/posts" meta authorization_needed: true end
# File lib/jsonapi/serializable/relationship/dsl.rb, line 77 def link(name, &block) @_links[name] = Link.as_jsonapi(@_exposures, &block) end
linkage(always: false, &block)
click to toggle source
@overload linkage(options = {}, &block)
Explicitly declare linkage data. @yieldreturn The resource linkage. @example linkage do @object.posts.map { |p| { id: p.id.to_s, type: 'posts' } } end
@overload linkage(options = {})
Forces standard linkage even if relationship not included. @example linkage always: true
# File lib/jsonapi/serializable/relationship/dsl.rb, line 35 def linkage(always: false, &block) @_include_linkage = always @_linkage_block = block end
meta(value = nil) { || ... }
click to toggle source
@overload meta(value)
Declare the meta information for this relationship. @param [Hash] value The meta information hash. @example meta paginated: true
@overload meta(&block)
Declare the meta information for this relationship. @yieldreturn [Hash] The meta information hash. @example meta do { paginated: true } end
# File lib/jsonapi/serializable/relationship/dsl.rb, line 55 def meta(value = nil) @_meta = value || yield end