active-resource-pagination 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/active_resource/pagination.rb +8 -2
- data/test/pagination_test.rb +4 -0
- metadata +1 -1
@@ -28,15 +28,21 @@ module ActiveResource
|
|
28
28
|
|
29
29
|
def decode(json)
|
30
30
|
meta = super(json)
|
31
|
-
if meta.is_a?(Hash)
|
31
|
+
if meta.is_a?(Hash) && meta['total_pages']
|
32
32
|
list = PagedArray.new(meta[collection_name])
|
33
33
|
|
34
34
|
list.total_pages = meta['total_pages']
|
35
35
|
list.current_page = meta['current_page']
|
36
36
|
|
37
|
+
list
|
38
|
+
elsif meta.is_a?(Array)
|
39
|
+
list = PagedArray.new(meta)
|
40
|
+
|
41
|
+
list.total_pages = 1
|
42
|
+
list.current_page = 1
|
43
|
+
|
37
44
|
list
|
38
45
|
else
|
39
|
-
# unexpected result, fall back to default behavior
|
40
46
|
meta
|
41
47
|
end
|
42
48
|
end
|
data/test/pagination_test.rb
CHANGED