Sha256: 6175f818696be4b7bcb5cb567655a7d02f0378463a2596da80f2c961997d5b5b
Contents?: true
Size: 707 Bytes
Versions: 21
Compression:
Stored size: 707 Bytes
Contents
module BaseCRM class PaginatedResource include Enumerable attr_reader :current_page def initialize(service, *args) raise TypeError unless service.respond_to?(:where) @service = service @args = args @options = args.last.kind_of?(Hash) ? args.pop : {} end def each(&block) return to_enum(:each) unless block_given? current_page = 1 per_page = 25 search_options = @options.merge(page: current_page, per_page: per_page) until (resources = @service.where(*@args, search_options)).empty? resources.each(&block) current_page += 1 search_options[:page] = current_page end self end end end
Version data entries
21 entries across 21 versions & 1 rubygems