Module: HALPresenter::Serializer

Included in:
HALPresenter
Defined in:
lib/hal_presenter/serializer.rb

Defined Under Namespace

Classes: Error

Instance Method Summary collapse

Instance Method Details

#to_collection(resources = [], options = {}) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/hal_presenter/serializer.rb', line 33

def to_collection(resources = [], options = {})
  unless can_serialize_collection?
    raise Error,
      "Trying to serialize a collection using #{self} which has no collection info. " \
      "Add a 'collection' spec to the serializer or use another serializer"
  end
  options[:paginate] = HALPresenter.paginate unless options.key? :paginate
  options[:_depth] ||= 0
  hash = to_collection_hash(resources, options)
  move_curies_to_top! hash
  JSON.generate(hash)
end

#to_hal(resource = nil, options = {}) ⇒ Object



26
27
28
29
30
31
# File 'lib/hal_presenter/serializer.rb', line 26

def to_hal(resource = nil, options = {})
  options[:_depth] ||= 0
  hash = to_hash(resource, options)
  move_curies_to_top! hash
  JSON.generate(hash)
end