Module: Roar::JSON::HAL::Links::ClassMethods

Defined in:
lib/roar/json/hal.rb

Instance Method Summary collapse

Instance Method Details

#curies(&block) ⇒ Object

Add a CURIEs link section as defined in

curies do

[{:name => :doc,
  :href => "//docs/{rel}",
  :templated => true}
]

end



188
189
190
# File 'lib/roar/json/hal.rb', line 188

def curies(&block)
  links(:curies, &block)
end

Use this to define link arrays. It accepts the shared rel attribute and an array of options per link object.

links :self do
  [{:lang => "en", :href => "http://en.hit"},
   {:lang => "de", :href => "http://de.hit"}]
end


174
175
176
177
178
# File 'lib/roar/json/hal.rb', line 174

def links(options, &block)
  options = {:rel => options} if options.is_a?(Symbol) || options.is_a?(String)
  options[:array] = true
  link(options, &block)
end


158
159
160
161
162
163
164
165
166
# File 'lib/roar/json/hal.rb', line 158

def links_definition_options
  {
    # collection: false,
    :as       => :_links,
    decorator: Links::Representer,
    instance: ->(*) { Array.new }, # defined in InstanceMethods as this is executed in represented context.
    :exec_context => :decorator,
  }
end