stretchy 0.5.0 → 0.5.1

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: 0a99cb1c541bd391ec2a66a6c308303c472a40a9
4
- data.tar.gz: 22f57aaec49d2e92582ddb592517f821380ecc1c
3
+ metadata.gz: 0c3818aa28e0d5d43fa9b1abc168571856081382
4
+ data.tar.gz: 31e8a84723d588e7b5e0ffff48c205bf9a96a514
5
5
  SHA512:
6
- metadata.gz: f7719795d07bdbccb23c74dc0dc50dcaec510fb4aea06d3a8a90d4eb3754a388e043073128ff7033a4c36a32866b584333fb4a4b999127bbbbf7f7f6e7bc19c5
7
- data.tar.gz: fd7e7600d8d60680147ff72b8745817271fec832b28611e01f81babc0798d9de71170c12c5b36c81764dbb7b7975c380e5c0252e0b54259ed58fe1c0213b098d
6
+ metadata.gz: a43550179be297d7e581075223a43781cf24f23e9eca3f379256492186107154cdd76d398184efff9f3b1ac9c4ee11c37c4b576dd90c2c8e0aac0366172f06ec
7
+ data.tar.gz: 9cd2d2c2344b52bcf20cb4e852cc20514f48cc1bc80aca17a35b51a59370b5c74dd13edbb08e60a996c0a1672e304627a846020d4968169c5e58153acf7e8810
data/lib/stretchy/api.rb CHANGED
@@ -11,6 +11,21 @@ module Stretchy
11
11
 
12
12
  attr_reader :collector, :root, :context
13
13
 
14
+ delegate [
15
+ :total,
16
+ :total_count,
17
+ :length,
18
+ :size,
19
+ :total_pages,
20
+ :results,
21
+ :hits,
22
+ :to_a,
23
+ :ids,
24
+ :scores,
25
+ :explanations,
26
+ :aggregations
27
+ ] => :results_obj
28
+
14
29
  def initialize(options = {})
15
30
  @collector = AndCollector.new(options[:nodes] || [], query: true)
16
31
  @root = options[:root] || {}
@@ -42,6 +57,12 @@ module Stretchy
42
57
  add_root from: start * per, size: per
43
58
  end
44
59
 
60
+ def per(num = nil)
61
+ return limit if num.nil?
62
+ add_root size: [num.to_i, 1].max
63
+ end
64
+ alias :per_page :per
65
+
45
66
  def current_page
46
67
  Utils.current_page(offset, limit)
47
68
  end
@@ -154,10 +175,12 @@ module Stretchy
154
175
  @results ||= Results.new request, response
155
176
  end
156
177
 
178
+ def count
179
+ results_obj.ids.count
180
+ end
181
+
157
182
  def method_missing(method, *args, &block)
158
- if results_obj.respond_to?(method)
159
- results_obj.send(method, *args, &block)
160
- elsif collector.respond_to?(method)
183
+ if collector.respond_to?(method)
161
184
  collector.send(method, *args, &block)
162
185
  else
163
186
  super
@@ -76,6 +76,7 @@ module Stretchy
76
76
 
77
77
  def params_to_queries(params, context = default_context)
78
78
  params.map do |field, val|
79
+ val = val.join if val.is_a? Array
79
80
  Node.new({match: {field => val}}, context)
80
81
  end
81
82
  end
@@ -1,3 +1,3 @@
1
1
  module Stretchy
2
- VERSION = "0.5.0"
2
+ VERSION = "0.5.1"
3
3
  end
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.5.0
4
+ version: 0.5.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-09-09 00:00:00.000000000 Z
11
+ date: 2015-10-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: elasticsearch