Module: JSONAPI::Serializable::Resource::Links::DSL

Defined in:
lib/jsonapi/serializable/resource/links.rb

Overview

DSL methods for declaring resource links.

Instance Method Summary collapse

Instance Method Details

#inherited(klass) ⇒ Object



35
36
37
38
# File 'lib/jsonapi/serializable/resource/links.rb', line 35

def inherited(klass)
  super
  klass.link_blocks = link_blocks.dup
end

Declare a link for this resource. The properties of the link are set

by providing a block in which the DSL methods of
+JSONAPI::Serializable::Link+ are called, or the value of the link
is returned directly.

Examples:

link(:self) do
  "http://api.example.com/users/#{@user.id}"
end
link(:self) do
  href "http://api.example.com/users/#{@user.id}"
  meta is_self: true
end

Parameters:

  • name (Symbol)

    The key of the link.

Yield Returns:

  • (Hash, String, nil)

    The block to compute the value, if any.

See Also:

  • JSONAPI::Serialiable::Link


60
61
62
# File 'lib/jsonapi/serializable/resource/links.rb', line 60

def link(name, &block)
  link_blocks[name] = block
end