Module: Roar::Hypermedia
- Includes:
- LinkConfigsMethod
- Included in:
- JSON::JSONAPI::Resource::Representer
- Defined in:
- lib/roar/hypermedia.rb
Overview
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)
Defined Under Namespace
Modules: ClassMethods, LinkConfigsMethod Classes: Hyperlink, LinkCollection
Instance Attribute Summary collapse
-
#links ⇒ Object
this is only useful after parsing.
Class Method Summary collapse
-
.included(base) ⇒ Object
links= [Hyperlink, Hyperlink] is where parsing happens.
Methods included from LinkConfigsMethod
Instance Attribute Details
#links ⇒ Object
this is only useful after parsing.
45 46 47 |
# File 'lib/roar/hypermedia.rb', line 45 def links @links end |
Class Method Details
.included(base) ⇒ Object
links= [Hyperlink, Hyperlink] is where parsing happens.
37 38 39 |
# File 'lib/roar/hypermedia.rb', line 37 def self.included(base) base.extend ClassMethods end |