elasticband 0.1.5 → 0.1.6
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 +8 -8
- data/.gitignore +1 -0
- data/README.md +6 -1
- data/lib/elasticband/aggregation.rb +1 -1
- data/lib/elasticband/sort.rb +34 -15
- data/lib/elasticband/version.rb +1 -1
- data/spec/sort_spec.rb +17 -11
- metadata +1 -2
- data/Gemfile.lock +0 -73
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
YjdlOTdhMWJmYzYzNWJhY2E2MjMyNDAyNzg2YTkyYzVlMzFjYWMxYQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
Y2VmMzk3ZDAxYzE0OGIyYTcwNTFlMzdkMDRjYzU3MjVjYTJkMTMxMg==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YTkzNjAwYTM4ZjcxZjZmMjdjOGJmYzdiMGFmODc2OWJlZDJjNzRlODhhZDdk
|
10
|
+
NTkxYmViY2NkM2Y5NDhiNzcxYmZkYWMyNDhkYTEwNTA3NWZhY2UyN2RkM2Mz
|
11
|
+
YmJjODdkZjMyNTJiYjhlYzkyNzdjZGEwMGNkNDgxNjNhYzg4NzE=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZmRhZWRhZDg2YzQwYmNmZGNhZjMxYzM3ZWQ3ODY2MmIyMGFiOTA4MjAzZjkx
|
14
|
+
MTM3ZjNjMGRkODFjMTE5ZGY3ZmEzOTc2ZjcyZjNkMTZhZGQwYjAyODZiNDJk
|
15
|
+
ODEyNzI1YzhmYjhlYThjYzczZmVmMGEyOWMxMWRhM2FjODNmZWE=
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
# Elasticband
|
2
|
-
|
2
|
+
|
3
|
+
[](https://travis-ci.org/LoveMondays/elasticband)
|
4
|
+
[](https://codeclimate.com/github/LoveMondays/elasticband)
|
5
|
+
[](https://codeclimate.com/github/LoveMondays/elasticband/coverage)
|
6
|
+
[](http://badge.fury.io/rb/elasticband)
|
7
|
+
[](https://gemnasium.com/LoveMondays/elasticband)
|
3
8
|
|
4
9
|
Query builder for [elasticsearch-rails gem](https://github.com/elastic/elasticsearch-rails)
|
5
10
|
|
data/lib/elasticband/sort.rb
CHANGED
@@ -9,32 +9,51 @@ module Elasticband
|
|
9
9
|
#
|
10
10
|
# #### Examples
|
11
11
|
# ```
|
12
|
-
# Sort.parse(sort:
|
12
|
+
# Sort.parse(sort: { name: :desc })
|
13
13
|
# => { sort: [{ name: :desc }] }
|
14
14
|
#
|
15
|
-
# Sort.parse(sort: [{ name: :asc }])
|
16
|
-
# => { sort: [{ name: :asc }] }
|
15
|
+
# Sort.parse(sort: [{ name: :desc }, { created_at: :asc }])
|
16
|
+
# => { sort: [{ name: :desc }, { created_at: :asc }] }
|
17
17
|
#
|
18
|
-
# Sort.parse(sort:
|
19
|
-
# => { sort: [{ name: :asc }] }
|
18
|
+
# Sort.parse(sort: '-name,+created_at,id')
|
19
|
+
# => { sort: [{ name: :desc }, { created_at: :asc }, { id: :asc }] }
|
20
20
|
#
|
21
|
-
# Sort.parse(sort: ['-name'])
|
22
|
-
# => { sort: [{ name: :desc }] }
|
21
|
+
# Sort.parse(sort: ['-name', '+created_at', 'id'])
|
22
|
+
# => { sort: [{ name: :desc }, { created_at: :asc }, { id: :asc }] }
|
23
23
|
# ```
|
24
24
|
def parse(options)
|
25
|
-
options[:sort].
|
25
|
+
new(options[:sort]).parse
|
26
26
|
end
|
27
|
+
end
|
28
|
+
|
29
|
+
attr_reader :sort_by
|
27
30
|
|
28
|
-
|
31
|
+
def initialize(sort_by)
|
32
|
+
@sort_by = sort_by
|
33
|
+
end
|
29
34
|
|
30
|
-
|
31
|
-
|
35
|
+
def parse
|
36
|
+
return if sort_by.blank?
|
37
|
+
return [sort_by] if sort_by.is_a?(Hash)
|
32
38
|
|
33
|
-
|
34
|
-
|
39
|
+
@sort_by = sort_by.split(','.freeze) if sort_by.is_a?(String)
|
40
|
+
sort_by.map { |param| parse_param(param) }
|
41
|
+
end
|
35
42
|
|
36
|
-
|
37
|
-
|
43
|
+
private
|
44
|
+
|
45
|
+
def parse_param(param)
|
46
|
+
return param if param.is_a?(Hash)
|
47
|
+
|
48
|
+
{ field(param).to_sym => direction(param) }
|
49
|
+
end
|
50
|
+
|
51
|
+
def field(param)
|
52
|
+
param.start_with?('-'.freeze) || param.start_with?('+'.freeze) ? param[1..-1] : param
|
53
|
+
end
|
54
|
+
|
55
|
+
def direction(param)
|
56
|
+
param.start_with?('-'.freeze) ? :desc : :asc
|
38
57
|
end
|
39
58
|
end
|
40
59
|
end
|
data/lib/elasticband/version.rb
CHANGED
data/spec/sort_spec.rb
CHANGED
@@ -4,28 +4,34 @@ RSpec.describe Elasticband::Sort do
|
|
4
4
|
describe '.parse' do
|
5
5
|
subject { described_class.parse(sort: sort_params) }
|
6
6
|
|
7
|
-
context '
|
8
|
-
let(:sort_params) {
|
7
|
+
context 'when sort param nil' do
|
8
|
+
let(:sort_params) { nil }
|
9
|
+
|
10
|
+
it { is_expected.to be nil }
|
11
|
+
end
|
12
|
+
|
13
|
+
context 'when sort is a hash' do
|
14
|
+
let(:sort_params) { { name: :desc } }
|
9
15
|
|
10
16
|
it { is_expected.to eq([{ name: :desc }]) }
|
11
17
|
end
|
12
18
|
|
13
|
-
context '
|
14
|
-
let(:sort_params) { [
|
19
|
+
context 'when sort is an array of hashes' do
|
20
|
+
let(:sort_params) { [{ name: :desc }, { created_at: :asc }] }
|
15
21
|
|
16
|
-
it { is_expected.to eq([{ name: :asc }]) }
|
22
|
+
it { is_expected.to eq([{ name: :desc }, { created_at: :asc }]) }
|
17
23
|
end
|
18
24
|
|
19
|
-
context '
|
20
|
-
let(:sort_params) {
|
25
|
+
context 'when sort is a string' do
|
26
|
+
let(:sort_params) { '-name,+created_at,id' }
|
21
27
|
|
22
|
-
it { is_expected.to eq([{ name: :desc }]) }
|
28
|
+
it { is_expected.to eq([{ name: :desc }, { created_at: :asc }, { id: :asc }]) }
|
23
29
|
end
|
24
30
|
|
25
|
-
context '
|
26
|
-
let(:sort_params) { ['name'] }
|
31
|
+
context 'when sort is array of strings' do
|
32
|
+
let(:sort_params) { ['-name', '+created_at', 'id'] }
|
27
33
|
|
28
|
-
it { is_expected.to eq([{ name: :asc }]) }
|
34
|
+
it { is_expected.to eq([{ name: :desc }, { created_at: :asc }, { id: :asc }]) }
|
29
35
|
end
|
30
36
|
end
|
31
37
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: elasticband
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Glauber Campinho
|
@@ -109,7 +109,6 @@ files:
|
|
109
109
|
- .travis.yml
|
110
110
|
- CODE_OF_CONDUCT.md
|
111
111
|
- Gemfile
|
112
|
-
- Gemfile.lock
|
113
112
|
- LICENSE
|
114
113
|
- README.md
|
115
114
|
- Rakefile
|
data/Gemfile.lock
DELETED
@@ -1,73 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
elasticband (0.1.5)
|
5
|
-
activesupport
|
6
|
-
|
7
|
-
GEM
|
8
|
-
remote: https://rubygems.org/
|
9
|
-
specs:
|
10
|
-
activesupport (4.2.4)
|
11
|
-
i18n (~> 0.7)
|
12
|
-
json (~> 1.7, >= 1.7.7)
|
13
|
-
minitest (~> 5.1)
|
14
|
-
thread_safe (~> 0.3, >= 0.3.4)
|
15
|
-
tzinfo (~> 1.1)
|
16
|
-
ast (2.0.0)
|
17
|
-
astrolabe (1.3.0)
|
18
|
-
parser (>= 2.2.0.pre.3, < 3.0)
|
19
|
-
codeclimate-test-reporter (0.4.7)
|
20
|
-
simplecov (>= 0.7.1, < 1.0.0)
|
21
|
-
diff-lcs (1.2.5)
|
22
|
-
docile (1.1.5)
|
23
|
-
dotenv (2.0.2)
|
24
|
-
i18n (0.7.0)
|
25
|
-
json (1.8.3)
|
26
|
-
minitest (5.8.0)
|
27
|
-
parser (2.2.2.6)
|
28
|
-
ast (>= 1.1, < 3.0)
|
29
|
-
powerpack (0.1.1)
|
30
|
-
rainbow (2.0.0)
|
31
|
-
rake (10.4.2)
|
32
|
-
rspec (3.3.0)
|
33
|
-
rspec-core (~> 3.3.0)
|
34
|
-
rspec-expectations (~> 3.3.0)
|
35
|
-
rspec-mocks (~> 3.3.0)
|
36
|
-
rspec-core (3.3.1)
|
37
|
-
rspec-support (~> 3.3.0)
|
38
|
-
rspec-expectations (3.3.0)
|
39
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
40
|
-
rspec-support (~> 3.3.0)
|
41
|
-
rspec-mocks (3.3.1)
|
42
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
43
|
-
rspec-support (~> 3.3.0)
|
44
|
-
rspec-support (3.3.0)
|
45
|
-
rubocop (0.32.1)
|
46
|
-
astrolabe (~> 1.3)
|
47
|
-
parser (>= 2.2.2.5, < 3.0)
|
48
|
-
powerpack (~> 0.1)
|
49
|
-
rainbow (>= 1.99.1, < 3.0)
|
50
|
-
ruby-progressbar (~> 1.4)
|
51
|
-
ruby-progressbar (1.7.5)
|
52
|
-
simplecov (0.10.0)
|
53
|
-
docile (~> 1.1.0)
|
54
|
-
json (~> 1.8)
|
55
|
-
simplecov-html (~> 0.10.0)
|
56
|
-
simplecov-html (0.10.0)
|
57
|
-
thread_safe (0.3.5)
|
58
|
-
tzinfo (1.2.2)
|
59
|
-
thread_safe (~> 0.1)
|
60
|
-
|
61
|
-
PLATFORMS
|
62
|
-
ruby
|
63
|
-
|
64
|
-
DEPENDENCIES
|
65
|
-
codeclimate-test-reporter
|
66
|
-
dotenv
|
67
|
-
elasticband!
|
68
|
-
rake
|
69
|
-
rspec (~> 3.3.0)
|
70
|
-
rubocop
|
71
|
-
|
72
|
-
BUNDLED WITH
|
73
|
-
1.10.6
|