class Oat::Adapters::HAL
Public Instance Methods
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/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
Also aliased as: collection
entity(name, obj, serializer_class = nil, context_options = {}, &block)
click to toggle source
# 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 = {})
click to toggle source
# 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)
click to toggle source
# File lib/oat/adapters/hal.rb, line 13 def properties(&block) data.merge! yield_props(&block) end
property(key, value)
click to toggle source
# File lib/oat/adapters/hal.rb, line 17 def property(key, value) data[key] = value end
Also aliased as: meta
rel(rels)
click to toggle source
# File lib/oat/adapters/hal.rb, line 23 def rel(rels) # no-op to maintain interface compatibility with the Siren adapter end
Private Instance Methods
entity_name(name)
click to toggle source
# File lib/oat/adapters/hal.rb, line 40 def entity_name(name) # entity name may be an array, but HAL only uses the first name.respond_to?(:first) ? name.first : name end