class SimpleObjectSerialization::CollectionSerializer
Attributes
collection[R]
options[R]
serializer_class[R]
Public Class Methods
call(*params, **options, &block)
click to toggle source
# File lib/simple_object_serialization/collection_serializer.rb, line 13 def self.call(*params, **options, &block) new(*params, **options).call(&block) end
new(serializer_class, collection, options)
click to toggle source
# File lib/simple_object_serialization/collection_serializer.rb, line 7 def initialize(serializer_class, collection, options) @serializer_class = serializer_class @collection = collection @options = options end
Public Instance Methods
call()
click to toggle source
# File lib/simple_object_serialization/collection_serializer.rb, line 17 def call { data: data, meta: meta } end
Private Instance Methods
data()
click to toggle source
# File lib/simple_object_serialization/collection_serializer.rb, line 26 def data collection.map.with_index do |object, index| serializer_class.call(object, options.merge(index: index)) end end
meta()
click to toggle source
# File lib/simple_object_serialization/collection_serializer.rb, line 32 def meta Hash(options[:meta]).tap do |hash| hash.merge!(pagination) if collection.respond_to?(:current_page) end end
pagination()
click to toggle source
# File lib/simple_object_serialization/collection_serializer.rb, line 38 def pagination { total_count: collection.total_count, total_pages: collection.total_pages, per_page: collection.limit_value, prev_page: collection.prev_page, current_page: collection.current_page, next_page: collection.next_page } end