class Oat::Adapters::Siren

Public Class Methods

new(*args) click to toggle source
Calls superclass method Oat::Adapter::new
# File lib/oat/adapters/siren.rb, line 6
def initialize(*args)
  super
  data[:links] = []
  data[:entities] = []
  data[:actions] = []
end

Public Instance Methods

action(name, &block) click to toggle source
# File lib/oat/adapters/siren.rb, line 59
def action(name, &block)
  action = Action.new(name)
  block.call(action)

  data[:actions] << action.data
end
collection(name, collection, serializer_class = nil, context_options = {}, &block)
Alias for: entities
entities(name, collection, serializer_class = nil, context_options = {}, &block) click to toggle source
# File lib/oat/adapters/siren.rb, line 51
def entities(name, collection, serializer_class = nil, context_options = {}, &block)
  collection.each do |obj|
    entity name, obj, serializer_class, context_options, &block
  end
end
Also aliased as: collection
entity(name, obj, serializer_class = nil, context_options = {}, &block) click to toggle source
# File lib/oat/adapters/siren.rb, line 38
def entity(name, obj, serializer_class = nil, context_options = {}, &block)
  ent = serializer_from_block_or_class(obj, serializer_class, context_options, &block)
  if ent
    # use the name as the sub-entities rel to the parent resource.
    ent.rel(name)
    ent_hash = ent.to_hash

    unless data[:entities].include? ent_hash
      data[:entities] << ent_hash
    end
  end
end
meta(key, value)
Alias for: property
properties(&block) click to toggle source
# File lib/oat/adapters/siren.rb, line 28
def properties(&block)
  data[:properties].merge! yield_props(&block)
end
property(key, value) click to toggle source
# File lib/oat/adapters/siren.rb, line 32
def property(key, value)
  data[:properties][key] = value
end
Also aliased as: meta
rel(rels) click to toggle source

Sub-Entities have a required rel attribute github.com/kevinswiber/siren#rel

# File lib/oat/adapters/siren.rb, line 15
def rel(rels)
  # rel must be an array.
  data[:rel] = Array(rels)
end
type(*types) click to toggle source
# File lib/oat/adapters/siren.rb, line 20
def type(*types)
  data[:class] = types
end