Module: Shamu::JsonApi::BuilderMethods::Link

Included in:
Shamu::JsonApi::BaseBuilder, ErrorBuilder
Defined in:
lib/shamu/json_api/builder_methods/link.rb

Instance Method Summary collapse

Instance Method Details

Write a link to another resource.

Parameters:

  • name (String, Symbol)

    of the link.

  • url (String)
  • meta (Hash) (defaults to: nil)

    optional additional meta information.

Returns:

  • (self)


11
12
13
14
15
16
17
18
19
20
21
# File 'lib/shamu/json_api/builder_methods/link.rb', line 11

def link( name, url, meta: nil )
  links = ( output[:links] ||= {} )

  if meta # rubocop:disable Style/ConditionalAssignment
    links[ name.to_sym ] = { href: url, meta: meta }
  else
    links[ name.to_sym ] = url
  end

  self
end