sunspot-null_result 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +14 -1
- data/lib/sunspot/null_result/group.rb +15 -0
- data/lib/sunspot/null_result/grouped_collection.rb +28 -0
- data/lib/sunspot/null_result/hit.rb +6 -0
- data/lib/sunspot/null_result/version.rb +1 -1
- data/lib/sunspot/null_result.rb +14 -1
- data/sunspot-null_result.gemspec +1 -1
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3740ef1e7a405a20d92e8eb2781cc4a0444fd006
|
4
|
+
data.tar.gz: d793d2301d6c9604b14449d9b5c8655ad8d55424
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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
|
data/lib/sunspot/null_result.rb
CHANGED
@@ -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
|
data/sunspot-null_result.gemspec
CHANGED
@@ -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.
|
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.
|
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-
|
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.
|
91
|
+
version: 2.2.0
|
89
92
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
93
|
requirements:
|
91
94
|
- - ">="
|