sunspot-null_result 0.2.0 → 0.3.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: 00214e1bc2fb4fd5033831c647c0be5d4302b6b1
4
- data.tar.gz: 8d15d147a7e3024eb92e98737bc8d1e8d356d1d3
3
+ metadata.gz: 3740ef1e7a405a20d92e8eb2781cc4a0444fd006
4
+ data.tar.gz: d793d2301d6c9604b14449d9b5c8655ad8d55424
5
5
  SHA512:
6
- metadata.gz: 6cb5a1798107025c66a90c347426b0b5f59d80bb5e4678922ee567c77adbd488bec31e53dddf31366ae6a0348152c66c9e223f88ed7dd40ae546ae3654944e01
7
- data.tar.gz: 6fdf0660422525e586c62b7dec83dc885593a41c268c9576c352903ac7926da34f4b03cc9a4869e0f3531812e13e07659dfc887c061058a64924ba09f6bff3d9
6
+ metadata.gz: a1db5c946595913c4e1d485570d4fe89045a5a167664f61f4c2ec28373f23a72bce9e22df9a624a5189ea68b1e0316f15be00bc17f35797137c568a5adcf6e97
7
+ data.tar.gz: a5c34f56dfe2ebdd204414dfeee7ff149c4006dc4c0fb99dc21152e5e0e3407fdc6effa59b3b66505f3d8c952f247883822cb4851a6ca3df7b77e6b75035572a
data/README.md CHANGED
@@ -24,7 +24,7 @@ Or install it yourself as:
24
24
 
25
25
  ## Usage
26
26
 
27
- RSpec case:
27
+ RSpec examples:
28
28
 
29
29
  ```ruby
30
30
  RSpec.describe 'stubbed Solr result' do
@@ -34,11 +34,21 @@ RSpec.describe 'stubbed Solr result' do
34
34
  context 'with no records' do
35
35
  let(:records) { [] }
36
36
  # …
37
+
38
+ it 'supports grouping' do
39
+ # …
40
+ expect(search.group(:my_attribute)).to eql []
41
+ end
37
42
  end
38
43
 
39
44
  context 'with some records' do
40
45
  let(:records) { [MyModel.new, MyModel.new] }
41
46
  # …
47
+
48
+ it 'supports grouping' do
49
+ # …
50
+ expect(search.group(:my_attribute)).not_to be_empty
51
+ end
42
52
  end
43
53
  end
44
54
  ```
@@ -64,6 +74,9 @@ end
64
74
 
65
75
  ### HEAD (not yet released)
66
76
 
77
+ ### v0.3.0
78
+ * Support Sunspot grouping
79
+
67
80
  ### v0.2.0
68
81
  * Allow setting of pagination options and calculate dependent values accordingly
69
82
 
@@ -0,0 +1,15 @@
1
+ module Sunspot
2
+ class NullResult
3
+ class Group < Struct.new(:value, :collection)
4
+
5
+ def solr_docs
6
+ collection.map { |item| "#{item.class.to_s} #{item.id}" }
7
+ end
8
+
9
+ def hits
10
+ collection.map { |item| Hit.new item.id }
11
+ end
12
+
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,28 @@
1
+ module Sunspot
2
+ class NullResult
3
+ class GroupedCollection
4
+
5
+ include Enumerable
6
+
7
+ attr_reader :collection, :group_by
8
+
9
+ def initialize(collection, group_by = nil)
10
+ @collection = group_by.nil? ? [] : Array(collection)
11
+ @group_by = group_by || :itself
12
+ end
13
+
14
+ def to_a
15
+ grouped = collection.group_by(&group_by)
16
+
17
+ grouped.keys.map do |group_key|
18
+ Group.new(group_key, grouped[group_key])
19
+ end
20
+ end
21
+
22
+ def each(*args, &block)
23
+ to_a.each(*args, &block)
24
+ end
25
+
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,6 @@
1
+ module Sunspot
2
+ class NullResult
3
+ class Hit < Struct.new(:primary_key)
4
+ end
5
+ end
6
+ end
@@ -1,5 +1,5 @@
1
1
  module Sunspot
2
2
  class NullResult
3
- VERSION = "0.2.0"
3
+ VERSION = "0.3.0"
4
4
  end
5
5
  end
@@ -1,12 +1,16 @@
1
1
  require "sunspot/null_result/version"
2
+ require "sunspot/null_result/grouped_collection"
3
+ require "sunspot/null_result/group"
4
+ require "sunspot/null_result/hit"
2
5
 
3
6
  module Sunspot
4
7
  class NullResult
5
- attr_reader :collection, :options
8
+ attr_reader :collection, :options, :group_by
6
9
 
7
10
  def initialize(*collection, **options)
8
11
  @collection = collection.flatten
9
12
  @options = options
13
+ @group_by = nil
10
14
  end
11
15
 
12
16
  # Implements the interface of
@@ -62,5 +66,14 @@ module Sunspot
62
66
  PaginatedNullArray.new(collection, options)
63
67
  end
64
68
 
69
+ def group(group)
70
+ @group_by = group
71
+ self
72
+ end
73
+
74
+ def groups
75
+ GroupedCollection.new(collection, group_by).to_a
76
+ end
77
+
65
78
  end
66
79
  end
@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
19
19
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
20
  spec.require_paths = ["lib"]
21
21
 
22
- spec.required_ruby_version = ">= 2.1.0"
22
+ spec.required_ruby_version = ">= 2.2.0"
23
23
 
24
24
  spec.add_development_dependency "bundler", "~> 1.10"
25
25
  spec.add_development_dependency "rake", "~> 10.0"
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.2.0
4
+ version: 0.3.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: 2015-09-01 00:00:00.000000000 Z
11
+ date: 2015-09-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -71,6 +71,9 @@ files:
71
71
  - bin/console
72
72
  - bin/setup
73
73
  - lib/sunspot/null_result.rb
74
+ - lib/sunspot/null_result/group.rb
75
+ - lib/sunspot/null_result/grouped_collection.rb
76
+ - lib/sunspot/null_result/hit.rb
74
77
  - lib/sunspot/null_result/version.rb
75
78
  - sunspot-null_result.gemspec
76
79
  homepage: https://github.com/Absolventa/sunspot-null_result
@@ -85,7 +88,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
85
88
  requirements:
86
89
  - - ">="
87
90
  - !ruby/object:Gem::Version
88
- version: 2.1.0
91
+ version: 2.2.0
89
92
  required_rubygems_version: !ruby/object:Gem::Requirement
90
93
  requirements:
91
94
  - - ">="