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



41
42
43
44
45
46
# File 'lib/oat/adapters/siren.rb', line 41

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



34
35
36
37
38
# File 'lib/oat/adapters/siren.rb', line 34

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



29
30
31
32
# File 'lib/oat/adapters/siren.rb', line 29

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 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



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