Module: HALDecorator::Serializer
- Included in:
- HALDecorator
- Defined in:
- lib/hal_decorator/serializer.rb
Defined Under Namespace
Classes: Error
Instance Method Summary collapse
- #to_collection(resources = [], options = {}) ⇒ Object
- #to_hal(resource = nil, options = {}) ⇒ Object
Instance Method Details
#to_collection(resources = [], options = {}) ⇒ Object
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/hal_decorator/serializer.rb', line 31 def to_collection(resources = [], = {}) 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 [:paginate] = HALDecorator.paginate unless .key? :paginate hash = to_collection_hash(resources, ) JSON.generate(hash) end |
#to_hal(resource = nil, options = {}) ⇒ Object
26 27 28 29 |
# File 'lib/hal_decorator/serializer.rb', line 26 def to_hal(resource = nil, = {}) hash = to_hash(resource, ) JSON.generate(hash) end |