sorted 2.0.2 → 2.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -0
- data/lib/sorted.rb +26 -0
- data/lib/sorted/version.rb +1 -1
- data/spec/elasticsearch_query_spec.rb +20 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 47e5b8db73e27b5130e62753c00ec308e6c6886d
|
4
|
+
data.tar.gz: 4c8abeb0e9399f5d2558d202597199ed8d236bea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a1974de003bae9e48872f9652f209c5c374c0432d29635f1e169ef52ff3a0e626adff2bd2a8fa23ae583fe49cb98534e834ba82f36b1c285c456179f614ecb93
|
7
|
+
data.tar.gz: f9d8cba70836197f131ce03c3c36c35318284842d8a40aeb2ae3b4815d411c8e142949900257541b986be0c47f6ff97a06d3c0d5de7709aff3630ad15464f394
|
data/README.md
CHANGED
data/lib/sorted.rb
CHANGED
@@ -212,6 +212,32 @@ module Sorted
|
|
212
212
|
end
|
213
213
|
end
|
214
214
|
|
215
|
+
##
|
216
|
+
# Parses an Elasticsearch type set of order
|
217
|
+
#
|
218
|
+
# Parsing:
|
219
|
+
#
|
220
|
+
# params = [{ 'email' => {'order' => 'desc'}}]
|
221
|
+
# set = Sorted::ElasticsearchQuery.parse(params)
|
222
|
+
# set.to_a #=> [['email', 'desc']]
|
223
|
+
#
|
224
|
+
# Encoding:
|
225
|
+
#
|
226
|
+
# Sorted::ParamsQuery.encode(set) #=> [{ 'email' => {'order' => 'desc'}}]
|
227
|
+
#
|
228
|
+
|
229
|
+
class ElasticsearchQuery
|
230
|
+
extend Parse
|
231
|
+
|
232
|
+
def self.parse(raw)
|
233
|
+
Set.new(raw.each_with_object([]) { |hash, a| a << [hash.first.first, hash.first.last['order']] })
|
234
|
+
end
|
235
|
+
|
236
|
+
def self.encode(set)
|
237
|
+
set.to_a.each_with_object([]) { |f, a| a << { f.first => { 'order' => f.last } } }
|
238
|
+
end
|
239
|
+
end
|
240
|
+
|
215
241
|
##
|
216
242
|
# Parses an array of decoded query params
|
217
243
|
#
|
data/lib/sorted/version.rb
CHANGED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Sorted::ElasticsearchQuery, 'decode' do
|
4
|
+
it 'should decode elasticsearch order hash to into set' do
|
5
|
+
json = [{ 'email' => { 'order' => 'desc' } }, { 'phone' => { 'order' => 'asc' } }, { 'name' => { 'order' => 'desc' } }]
|
6
|
+
set = Sorted::ElasticsearchQuery.parse(json)
|
7
|
+
result = Sorted::Set.new([['email', 'desc'], ['phone', 'asc'], ['name', 'desc']])
|
8
|
+
|
9
|
+
expect(set).to eq(result)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe Sorted::ElasticsearchQuery, 'encode' do
|
14
|
+
it 'should encode set into elasticsearch order hash' do
|
15
|
+
set = Sorted::Set.new([['email', 'desc'], ['phone', 'asc'], ['name', 'desc']])
|
16
|
+
result = [{ 'email' => { 'order' => 'desc' } }, { 'phone' => { 'order' => 'asc' } }, { 'name' => { 'order' => 'desc' } }]
|
17
|
+
|
18
|
+
expect(Sorted::ElasticsearchQuery.encode(set)).to eq(result)
|
19
|
+
end
|
20
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sorted
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rufus Post
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-09-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -85,6 +85,7 @@ files:
|
|
85
85
|
- lib/sorted.rb
|
86
86
|
- lib/sorted/version.rb
|
87
87
|
- sorted.gemspec
|
88
|
+
- spec/elasticsearch_query_spec.rb
|
88
89
|
- spec/json_query_spec.rb
|
89
90
|
- spec/params_query_spec.rb
|
90
91
|
- spec/set_spec.rb
|