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
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