module Roar::Hypermedia

Define hypermedia links in your representations.

Example:

class Order
  include Roar:JSON

  property :id

  link :self do
    "http://orders/#{id}"
  end

If you want more attributes, just pass a hash to link.

link :rel => :next, :title => "Next, please!" do
  "http://orders/#{id}"
end

If you need dynamic attributes, the block can return a hash.

link :preview do
  {:href => image.url, :title => image.name}
end

Sometimes you need values from outside when the representation links are rendered. Just pass them to the render method, they will be available as block parameters.

link :self do |opts|
  "http://orders/#{opts[:id]}"
end

model.to_json(:id => 1)

Attributes

Public Class Methods

included(base) click to toggle source
# File lib/roar/hypermedia.rb, line 36
def self.included(base)
  base.extend ClassMethods
end

Public Instance Methods

Private Instance Methods