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


193
194
195
# File 'lib/roar/json/hal.rb', line 193

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

179
180
181
182
183
# File 'lib/roar/json/hal.rb', line 179

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

163
164
165
166
167
168
169
170
171
# File 'lib/roar/json/hal.rb', line 163

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