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

Defined in:
lib/roar/representer/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



214
215
216
# File 'lib/roar/representer/json/hal.rb', line 214

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


200
201
202
203
204
# File 'lib/roar/representer/json/hal.rb', line 200

def links(options, &block)
  options = {:rel => options} if options.is_a?(Symbol)
  options[:array] = true  # FIXME: we need to save this information somewhere.
  link(options, &block)
end


184
185
186
187
188
189
190
191
192
# File 'lib/roar/representer/json/hal.rb', line 184

def links_definition_options
  [:links,
    {
      :extend   => HAL::Links::LinkCollectionRepresenter,
      :instance => lambda { |*| LinkCollection.new(link_array_rels) }, # defined in InstanceMethods as this is executed in represented context.
      :decorator_scope => true
    }
  ]
end