Class: Oat::Adapters::Siren

Inherits:
Oat::Adapter show all
Defined in:
lib/oat/adapters/siren.rb

Defined Under Namespace

Classes: Action

Instance Method Summary collapse

Methods inherited from Oat::Adapter

#to_hash

Constructor Details

#initialize(*args) ⇒ Siren

Returns a new instance of Siren.



6
7
8
9
10
11
# File 'lib/oat/adapters/siren.rb', line 6

def initialize(*args)
  super
  data[:links] = []
  data[:entities] = []
  data[:actions] = []
end

Instance Method Details

#action(name, &block) ⇒ Object



44
45
46
47
48
49
# File 'lib/oat/adapters/siren.rb', line 44

def action(name, &block)
  action = Action.new(name)
  block.call(action)

  data[:actions] << action.data
end

#entities(name, collection, serializer_class = nil, context_options = {}, &block) ⇒ Object Also known as: collection



36
37
38
39
40
# File 'lib/oat/adapters/siren.rb', line 36

def entities(name, collection, serializer_class = nil, context_options = {}, &block)
  collection.each do |obj|
    entity name, obj, serializer_class, context_options, &block
  end
end

#entity(name, obj, serializer_class = nil, context_options = {}, &block) ⇒ Object



31
32
33
34
# File 'lib/oat/adapters/siren.rb', line 31

def entity(name, obj, serializer_class = nil, context_options = {}, &block)
  ent = serializer_from_block_or_class(obj, serializer_class, context_options, &block)
  data[:entities] << ent.to_hash if ent
end


17
18
19
# File 'lib/oat/adapters/siren.rb', line 17

def link(rel, opts = {})
  data[:links] << {:rel => [rel]}.merge(opts)
end

#properties(&block) ⇒ Object



21
22
23
# File 'lib/oat/adapters/siren.rb', line 21

def properties(&block)
  data[:properties].merge! yield_props(&block)
end

#property(key, value) ⇒ Object Also known as: meta



25
26
27
# File 'lib/oat/adapters/siren.rb', line 25

def property(key, value)
  data[:properties][key] = value
end

#type(*types) ⇒ Object



13
14
15
# File 'lib/oat/adapters/siren.rb', line 13

def type(*types)
  data[:class] = types
end