stretchy 0.3.0 → 0.3.1
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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0a7be2bbcc9690d42a0a9ca01601b4936b52dcf2
|
4
|
+
data.tar.gz: a53b3d3201f42f90f807324ec96b6d1049a4037c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1171e1dfe7ce1255a911bdd471d6c40aab58b1fa90ba88016d4dff49d0e463effcf9b1194d7e9470d3186e40905ffc7aca941c32a1c45458231aa2376c6993b1
|
7
|
+
data.tar.gz: 731cd339625a1a8ffbd398066d751a5424831f5f210eed1dd6ecd152cc27e93424042c8ad7da7d851858899c2b4cb05093382e1a41885dca4e3981949daee182
|
@@ -4,22 +4,25 @@ module Stretchy
|
|
4
4
|
module Filters
|
5
5
|
class NotFilter < Base
|
6
6
|
|
7
|
-
|
7
|
+
attr_reader :filters
|
8
8
|
|
9
|
-
|
10
|
-
filters = Array(filters)
|
9
|
+
contract :filters, { type: Base, array: true, required: true }
|
11
10
|
|
12
|
-
|
13
|
-
|
11
|
+
def initialize(*filters)
|
12
|
+
@filters = Array(filters).flatten
|
13
|
+
validate!
|
14
|
+
end
|
15
|
+
|
16
|
+
def filter
|
17
|
+
if @filters.count > 1
|
18
|
+
AndFilter.new(@filters)
|
14
19
|
else
|
15
|
-
@
|
20
|
+
@filters.first
|
16
21
|
end
|
17
|
-
|
18
|
-
validate!
|
19
22
|
end
|
20
23
|
|
21
24
|
def to_search
|
22
|
-
{ not:
|
25
|
+
{ not: filter.to_search }
|
23
26
|
end
|
24
27
|
end
|
25
28
|
end
|
@@ -2,14 +2,31 @@ module Stretchy
|
|
2
2
|
module Results
|
3
3
|
class Base
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
5
|
+
extend Forwardable
|
6
|
+
|
7
|
+
attr_reader :clause, :index_name
|
8
|
+
|
9
|
+
delegate [:type] => :clause
|
10
|
+
|
11
|
+
def initialize(clause)
|
12
|
+
@clause = clause
|
13
|
+
@index_name = clause.index_name || Stretchy.index_name
|
14
|
+
end
|
15
|
+
|
16
|
+
def limit
|
17
|
+
clause.get_limit
|
18
|
+
end
|
19
|
+
|
20
|
+
def offset
|
21
|
+
clause.get_offset
|
22
|
+
end
|
23
|
+
|
24
|
+
def request
|
25
|
+
@request ||= {query: clause.to_search}
|
9
26
|
end
|
10
27
|
|
11
28
|
def response
|
12
|
-
@response ||= Stretchy.search(type:
|
29
|
+
@response ||= Stretchy.search(type: type, body: request, from: offset, size: limit)
|
13
30
|
end
|
14
31
|
|
15
32
|
def ids
|
@@ -42,6 +59,4 @@ module Stretchy
|
|
42
59
|
|
43
60
|
end
|
44
61
|
end
|
45
|
-
end
|
46
|
-
|
47
|
-
require 'stretchy/results/null_results'
|
62
|
+
end
|
@@ -6,6 +6,24 @@ module Stretchy
|
|
6
6
|
# use this class when you don't want to actually run
|
7
7
|
# a search, or catch an exception or something
|
8
8
|
|
9
|
+
def initialize(clause = nil)
|
10
|
+
@clause = clause
|
11
|
+
@index_name = clause.index_name if clause.is_a?(Stretchy::Clauses::Base)
|
12
|
+
@index_name ||= Stretchy.index_name
|
13
|
+
end
|
14
|
+
|
15
|
+
def request
|
16
|
+
{}
|
17
|
+
end
|
18
|
+
|
19
|
+
def limit
|
20
|
+
0
|
21
|
+
end
|
22
|
+
|
23
|
+
def offset
|
24
|
+
0
|
25
|
+
end
|
26
|
+
|
9
27
|
def response
|
10
28
|
@response ||= {
|
11
29
|
'took' => 0,
|
@@ -21,20 +21,28 @@ module Stretchy
|
|
21
21
|
Stretchy::Clauses::Base.new(*args, &block)
|
22
22
|
end
|
23
23
|
|
24
|
-
def search(
|
25
|
-
|
26
|
-
|
24
|
+
def search(options = {})
|
25
|
+
params = {}
|
26
|
+
params[:index] = options[:index] || index_name
|
27
|
+
params[:type] = options[:type]
|
28
|
+
params[:fields] = Array(options[:fields]) if options[:fields]
|
29
|
+
params[:body] = options[:body]
|
27
30
|
|
28
|
-
client.search(
|
31
|
+
client.search(params)
|
29
32
|
end
|
30
33
|
|
31
|
-
def index(
|
32
|
-
|
33
|
-
|
34
|
+
def index(options = {})
|
35
|
+
index = options[:index] || index_name
|
36
|
+
type = options[:type]
|
37
|
+
body = options[:body]
|
38
|
+
id = options[:id] || options['id'] || body['id'] || body['_id'] || body[:id] || body[:_id]
|
39
|
+
client.index(index: index, type: type, id: id, body: body)
|
34
40
|
end
|
35
41
|
|
36
|
-
def bulk(
|
37
|
-
|
42
|
+
def bulk(options = {})
|
43
|
+
type = options[:type]
|
44
|
+
documents = options[:documents]
|
45
|
+
requests = documents.flat_map do |document|
|
38
46
|
id = document['id'] || document['_id'] || document[:id] || document[:_id]
|
39
47
|
[
|
40
48
|
{ index: { '_index' => index_name, '_type' => type, '_id' => id } },
|
@@ -17,6 +17,7 @@ module Stretchy
|
|
17
17
|
|
18
18
|
if options[:array]
|
19
19
|
self.class.assert_type(name, value, type: Array)
|
20
|
+
self.class.assert_required(name, value, {}) if options[:required]
|
20
21
|
end
|
21
22
|
|
22
23
|
ASSERTIONS.each do |assertion|
|
@@ -60,7 +61,7 @@ module Stretchy
|
|
60
61
|
end
|
61
62
|
|
62
63
|
def assert_required(name, value, options)
|
63
|
-
msg = "Expected to have param #{name}, but got
|
64
|
+
msg = "Expected to have param #{name}, but got an #{value.inspect}"
|
64
65
|
fail_assertion(msg) if is_empty?(value)
|
65
66
|
end
|
66
67
|
|
data/lib/stretchy/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stretchy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- agius
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-05-
|
11
|
+
date: 2015-05-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: elasticsearch
|