rubberband 0.9.5 → 0.9.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -37,13 +37,24 @@ module ElasticSearch
37
37
  def total_pages
38
38
  (total_entries / per_page.to_f).ceil
39
39
  end
40
+
41
+ def offset
42
+ per_page * (current_page - 1)
43
+ end
44
+
40
45
  alias_method :page_count, :total_pages
46
+
47
+ # Kaminari support
48
+ alias_method :limit_value, :per_page
49
+ alias_method :num_pages, :total_pages
50
+ alias_method :offset_value, :offset
41
51
  end
42
52
 
43
53
 
44
54
  class Hits
45
55
  include Pagination
46
56
  attr_reader :hits, :total_entries, :_shards, :response, :facets, :scroll_id
57
+ alias_method :total_count, :total_entries
47
58
 
48
59
  def initialize(response, options={})
49
60
  @response = response
@@ -1,3 +1,3 @@
1
1
  module ElasticSearch
2
- VERSION = "0.9.5"
2
+ VERSION = "0.9.6"
3
3
  end
@@ -27,7 +27,8 @@ describe ElasticSearch::Api::Hits do
27
27
 
28
28
  it { should respond_to(:response) }
29
29
 
30
- its(:total_entries) { should == response["hits"]["hits"].size }
30
+ its(:total_entries) { should == response["hits"]["hits"].size } # will_paginate
31
+ its(:total_count) { should == response["hits"]["hits"].size } # kaminari
31
32
 
32
33
  it "should instantiate hits in order" do
33
34
  response["hits"]["hits"].each_with_index do |hit, i|
@@ -58,10 +59,17 @@ describe ElasticSearch::Api::Hits do
58
59
 
59
60
  subject { described_class.new(response, {:page => page, :per_page => per_page}) }
60
61
 
62
+ # will_paginate
61
63
  its(:total_pages) { should == (response["hits"]["total"] / per_page.to_f).ceil }
62
64
  its(:next_page) { should == (page + 1) }
63
65
  its(:previous_page) { should == (page - 1) }
64
66
  its(:current_page) { should == page }
65
67
  its(:per_page) { should == per_page }
68
+ its(:offset) { should == per_page * (page - 1) }
69
+
70
+ # kaminari
71
+ its(:limit_value) { should == per_page }
72
+ its(:num_pages) { should == (response["hits"]["total"] / per_page.to_f).ceil }
73
+ its(:offset_value) { should == per_page * (page - 1) }
66
74
  end
67
75
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubberband
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.5
4
+ version: 0.9.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-09-10 00:00:00.000000000 Z
12
+ date: 2013-01-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: faraday
@@ -206,4 +206,3 @@ test_files:
206
206
  - spec/support/exception_client.rb
207
207
  - spec/support/timeout_retrying_client.rb
208
208
  - spec/type_spec.rb
209
- has_rdoc: