Class: Oat::Adapters::HAL
Instance Method Summary
collapse
-
#entities(name, collection, serializer_class = nil, context_options = {}, &block) ⇒ Object
(also: #collection)
-
#entity(name, obj, serializer_class = nil, context_options = {}, &block) ⇒ Object
-
#link(rel, opts = {}) ⇒ Object
-
#properties(&block) ⇒ Object
-
#property(key, value) ⇒ Object
(also: #meta)
-
#rel(rels) ⇒ Object
#initialize, #to_hash
Constructor Details
This class inherits a constructor from Oat::Adapter
Instance Method Details
#entities(name, collection, serializer_class = nil, context_options = {}, &block) ⇒ Object
Also known as:
collection
32
33
34
35
36
37
|
# File 'lib/oat/adapters/hal.rb', line 32
def entities(name, collection, serializer_class = nil, context_options = {}, &block)
data[:_embedded][entity_name(name)] = collection.map do |obj|
entity_serializer = serializer_from_block_or_class(obj, serializer_class, context_options, &block)
entity_serializer ? entity_serializer.to_hash : nil
end
end
|
#entity(name, obj, serializer_class = nil, context_options = {}, &block) ⇒ Object
27
28
29
30
|
# File 'lib/oat/adapters/hal.rb', line 27
def entity(name, obj, serializer_class = nil, context_options = {}, &block)
entity_serializer = serializer_from_block_or_class(obj, serializer_class, context_options, &block)
data[:_embedded][entity_name(name)] = entity_serializer ? entity_serializer.to_hash : nil
end
|
#link(rel, opts = {}) ⇒ Object
5
6
7
8
9
10
11
|
# File 'lib/oat/adapters/hal.rb', line 5
def link(rel, opts = {})
if opts.is_a?(Array)
data[:_links][rel] = opts.select { |link_obj| link_obj.include?(:href) }
else
data[:_links][rel] = opts if opts[:href]
end
end
|
#properties(&block) ⇒ Object
13
14
15
|
# File 'lib/oat/adapters/hal.rb', line 13
def properties(&block)
data.merge! yield_props(&block)
end
|
#property(key, value) ⇒ Object
Also known as:
meta
17
18
19
|
# File 'lib/oat/adapters/hal.rb', line 17
def property(key, value)
data[key] = value
end
|
#rel(rels) ⇒ Object
23
24
25
|
# File 'lib/oat/adapters/hal.rb', line 23
def rel(rels)
end
|