lib/tickethub/collection.rb in tickethub-0.2.15 vs lib/tickethub/collection.rb in tickethub-0.2.17

- old
+ new

@@ -1,10 +1,14 @@ require 'cgi' require_relative 'helpers' module Tickethub class Collection < Enumerator + + DEFAULT_LIMIT = 25.freeze + DEFAULT_OFFSET = 0.freeze + attr_accessor :cache attr_reader :count, :endpoint, :params def initialize(endpoint, klass, params = {}) @params = params.dup @@ -51,22 +55,20 @@ offset(count - 1).first end def limit(value = nil) if value.nil? - reload! if @limit.nil? - return @limit + return (@limit || params[:offset] || DEFAULT_LIMIT).to_i else self.class.new endpoint, @klass, params.merge(limit: value) end end def offset(value = nil) if value.nil? - reload! if @offset.nil? - return @offset + return (@offset || params[:offset] || DEFAULT_OFFSET).to_i else self.class.new endpoint, @klass, params.merge(offset: value) end end @@ -120,14 +122,9 @@ count.zero? end def any?(&block) block_given?? super : ! empty? - end - - def limit - self.reload! if @limit.nil? - return @limit end def count self.reload! if @count.nil? return @count \ No newline at end of file