Sha256: e81846299626c732fb343ac3c150feeaa079a1c03f7c815ff4331aae0bb27079
Contents?: true
Size: 969 Bytes
Versions: 7
Compression:
Stored size: 969 Bytes
Contents
module Kinescope class PaginationResource include Enumerable attr_reader :action, :args, :resource attr_accessor :page, :per_page, :total def initialize(action, resource, *args) @action = action @resource = resource @args = args @collection = [] @page = nil @per_page = nil @total = nil end def [](index) @collection[index] end def each(&block) handle_response if total.nil? return to_enum(:each) unless block_given? @collection.each { |element| yield(element) } self end private def handle_response invoker = ResourceKit::ActionInvoker.new(action, resource, *args) @collection = invoker.handle_response meta = Kinescope::MetaMapping.extract_single(invoker.response.body, :read) self.page = meta.pagination.page self.per_page = meta.pagination.per_page self.total = meta.pagination.total end end end
Version data entries
7 entries across 7 versions & 1 rubygems