Module: HALPresenter::Serializer
- Included in:
- HALPresenter
- Defined in:
- lib/hal_presenter/serializer.rb
Defined Under Namespace
Classes: Error
Class Method Summary collapse
Instance Method Summary collapse
- #to_collection(resources = [], options = {}) ⇒ Object
- #to_hal(resource = nil, options = {}) ⇒ Object
Class Method Details
.included(base) ⇒ Object
31 32 33 |
# File 'lib/hal_presenter/serializer.rb', line 31 def self.included(base) base.extend(ClassMethods) end |
Instance Method Details
#to_collection(resources = [], options = {}) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/hal_presenter/serializer.rb', line 43 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 = .dup [:paginate] = HALPresenter.paginate unless .key? :paginate [:_depth] ||= 0 hash = to_collection_hash(resources, ) move_curies_to_root! hash JSON.generate(hash) end |
#to_hal(resource = nil, options = {}) ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/hal_presenter/serializer.rb', line 35 def to_hal(resource = nil, = {}) = .dup [:_depth] ||= 0 hash = to_hash(resource, ) move_curies_to_root! hash JSON.generate(hash) end |