From 5348148fc7b700f145f495675c0e6eace50941f4 Mon Sep 17 00:00:00 2001 From: Lilia Markham Date: Wed, 22 Feb 2012 17:36:11 -0800 Subject: [PATCH] Store total counts on FetchingArray when fb returns a "count" attribute Previously we were accessing the FetchingArray.count method, which was returning the number of entries currently in the array, rather than the total number of available entries. When displaying statistics, this makes our numbers look small and sad. When building a fetching array we now store a "count" attribute if present in the total_count attribute. --- lib/mogli/client.rb | 1 + lib/mogli/fetching_array.rb | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/mogli/client.rb b/lib/mogli/client.rb index 5ab1abd..49697a4 100644 --- a/lib/mogli/client.rb +++ b/lib/mogli/client.rb @@ -177,6 +177,7 @@ def extract_fetching_array(hash,klass) f.concat(hash["data"]) f.client = self f.classes = Array(klass) + f.total_count = hash["count"] if paging=hash["paging"] f.next_url = URI.encode paging["next"] unless paging["next"].nil? f.previous_url = URI.encode paging["previous"] unless paging["previous"].nil? diff --git a/lib/mogli/fetching_array.rb b/lib/mogli/fetching_array.rb index 56dc190..4ff98cb 100644 --- a/lib/mogli/fetching_array.rb +++ b/lib/mogli/fetching_array.rb @@ -1,6 +1,6 @@ module Mogli class FetchingArray < Array - attr_accessor :next_url, :previous_url, :client, :classes + attr_accessor :next_url, :previous_url, :client, :classes, :total_count def fetch_next return [] if next_url.nil? || next_url.empty?