lib/zendesk_api/collection.rb in zendesk_api-0.1.11 vs lib/zendesk_api/collection.rb in zendesk_api-0.2.1

- old
+ new

@@ -82,11 +82,11 @@ end # @return [Number] The total number of resources server-side (disregarding pagination). def count fetch - @count + @count || -1 end # Changes the per_page option. Returns self, so it can be chained. No execution. # @return [Collection] self def per_page(count) @@ -101,10 +101,18 @@ clear_cache if number @options["page"] = number self end + def first_page? + !@options["page"] || @options["page"].to_i <= 1 + end + + def last_page? + !@options["page"] || @options["page"].to_i * @options["per_page"].to_i >= count + end + # Saves all newly created resources stored in this collection. # @return [Collection] self def save if @resources @resources.map! do |item| @@ -280,19 +288,22 @@ opts.merge!(:collection_path => @collection_path.dup.push(name)) self.class.new(@client, @resource_class, @options.merge(opts)) end end - alias :orig_to_s :to_s - # @private def to_s if @resources @resources.inspect else - orig_to_s + inspect = [] + inspect << "options=#{@options.inspect}" if @options.any? + inspect << "path=#{path}" + "#{Inflection.singular(@resource)} collection [#{inspect.join(",")}]" end end + + alias :to_str :to_s private def set_page_and_count(body) @count = (body["count"] || @resources.size).to_i