sunspot-null_result 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4b8e4609433f1dd0ac6c3eb45dfc7df567ad9fae
4
- data.tar.gz: e106556c917db3e3ad8af59ffc77a693ea9694f8
3
+ metadata.gz: 5593247f70866607e0f1bf99f8c1b4af2a06291c
4
+ data.tar.gz: d962f60f617748db6bc47c79a0307cc7f1b176c6
5
5
  SHA512:
6
- metadata.gz: 7b694c5833779caad543619f0cd72255e41a068b4baab3c44d461fb440424ea84796a196b6861ecb1d129025fbeff3cbf5979411a44dd6dc1460671e761fadcd
7
- data.tar.gz: b78b2497e98968957a78119d60afdf403f3531d838806d39a0e176aee43e42e3e39dbd0f8430a8efa2dcc523574d2e069c1ce5aa0dae6edfaefc63445f3e695d
6
+ metadata.gz: 46dbffb97edad6bddda7c50dbefc000c4a84a97184860f515c25979789451917608974a52b5ecd701b2a8f58df491f29018d2d47ffbecf10cd5b8468348d96b7
7
+ data.tar.gz: b174444cce9d70544f68b67caf10ccca398625863a20f5501670866dcb8d86e8ce095062523e6921bedd6d9ed0be1332003ac485ff9796872d0e5964828102c9
data/README.md CHANGED
@@ -74,6 +74,9 @@ end
74
74
 
75
75
  ### HEAD (not yet released)
76
76
 
77
+ ### v0.6.0
78
+ * Support kaminari-paginated enumerables
79
+
77
80
  ### v0.5.0
78
81
  * Build on newer MRI version
79
82
  * Add Sunspot::NullResult#total and #facet
@@ -0,0 +1,72 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Sunspot
4
+ class NullResult
5
+
6
+ # Implements the interface of
7
+ # https://github.com/sunspot/sunspot/blob/master/sunspot_rails/lib/sunspot/rails/stub_session_proxy.rb
8
+ class PaginatedNullArray < Array
9
+ attr_reader :per_page
10
+
11
+ def initialize(collection, current_page: 1, per_page: 1, offset: nil)
12
+ super(collection)
13
+ @current_page = current_page.to_i
14
+ @per_page = per_page.to_i
15
+ @offset = offset
16
+ @_collection = collection
17
+ end
18
+
19
+ alias limit_value per_page
20
+
21
+ def size
22
+ if @_collection.respond_to?(:total_count)
23
+ @_collection.total_count
24
+ else
25
+ super
26
+ end
27
+ end
28
+ alias total_count size
29
+
30
+ def total_pages
31
+ if @_collection.respond_to?(:total_pages)
32
+ @_collection.total_pages
33
+ else
34
+ [(size/per_page.to_f).ceil, 1].max
35
+ end
36
+ end
37
+ alias num_pages total_pages
38
+
39
+ def current_page
40
+ if @_collection.respond_to?(:current_page)
41
+ @_collection.current_page
42
+ else
43
+ @current_page
44
+ end
45
+ end
46
+
47
+ def prev_page
48
+ (current_page-1) if current_page > 1
49
+ end
50
+
51
+ def next_page
52
+ (current_page+1) if total_pages > current_page
53
+ end
54
+
55
+ def first_page?
56
+ true
57
+ end
58
+
59
+ def last_page?
60
+ true
61
+ end
62
+
63
+ def out_of_bounds?
64
+ false
65
+ end
66
+
67
+ def offset
68
+ @offset || 0
69
+ end
70
+ end
71
+ end
72
+ end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
  module Sunspot
3
3
  class NullResult
4
- VERSION = "0.5.0"
4
+ VERSION = "0.6.0"
5
5
  end
6
6
  end
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
  require "sunspot/null_result/version"
3
+ require "sunspot/null_result/paginated_null_array"
3
4
  require "sunspot/null_result/grouped_collection"
4
5
  require "sunspot/null_result/group"
5
6
  require "sunspot/null_result/hit"
@@ -9,56 +10,12 @@ module Sunspot
9
10
  class NullResult
10
11
  attr_reader :collection, :options, :group_by
11
12
 
12
- def initialize(*collection, **options)
13
- @collection = collection.flatten
13
+ def initialize(collection = [], **options)
14
+ @collection = collection
14
15
  @options = options
15
16
  @group_by = nil
16
17
  end
17
18
 
18
- # Implements the interface of
19
- # https://github.com/sunspot/sunspot/blob/master/sunspot_rails/lib/sunspot/rails/stub_session_proxy.rb
20
- class PaginatedNullArray < Array
21
- attr_reader :current_page, :per_page
22
-
23
- def initialize(collection, current_page: 1, per_page: 1)
24
- super(collection)
25
- @current_page = current_page
26
- @per_page = per_page
27
- end
28
-
29
- alias total_count size
30
- alias limit_value per_page
31
-
32
- def total_pages
33
- [(size/per_page.to_f).ceil, 1].max
34
- end
35
- alias num_pages total_pages
36
-
37
- def prev_page
38
- (current_page-1) if current_page > 1
39
- end
40
-
41
- def next_page
42
- (current_page+1) if total_pages > current_page
43
- end
44
-
45
- def first_page?
46
- true
47
- end
48
-
49
- def last_page?
50
- true
51
- end
52
-
53
- def out_of_bounds?
54
- false
55
- end
56
-
57
- def offset
58
- 0
59
- end
60
- end
61
-
62
19
  def hits
63
20
  PaginatedNullArray.new(collection, options)
64
21
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sunspot-null_result
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carsten Zimmermann
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-09-27 00:00:00.000000000 Z
11
+ date: 2017-01-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -75,6 +75,7 @@ files:
75
75
  - lib/sunspot/null_result/group.rb
76
76
  - lib/sunspot/null_result/grouped_collection.rb
77
77
  - lib/sunspot/null_result/hit.rb
78
+ - lib/sunspot/null_result/paginated_null_array.rb
78
79
  - lib/sunspot/null_result/version.rb
79
80
  - sunspot-null_result.gemspec
80
81
  homepage: https://github.com/Absolventa/sunspot-null_result
@@ -97,7 +98,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
97
98
  version: '0'
98
99
  requirements: []
99
100
  rubyforge_project:
100
- rubygems_version: 2.5.1
101
+ rubygems_version: 2.6.3
101
102
  signing_key:
102
103
  specification_version: 4
103
104
  summary: Provides a standalone mock result for Solr searches