dredd 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/dredd/dsl/aggregate.rb +4 -1
- data/lib/dredd/dsl/predicate.rb +25 -0
- data/lib/dredd/version.rb +1 -1
- data/spec/dredd/query_spec.rb +3 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b0d4e39388a55b8ef0bf7410e33abcb3c544a577
|
4
|
+
data.tar.gz: e1582407cd7fa935bb50e825a790fa75192475cd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3ee9456d383cefee40908ea2e3b347c63023f2e38610295f95abc9b30ba9ebb47ffd64de2b9ab55a8dcd15f44c43bc028f47c7f16be76b6cb7ff02408ad4e760
|
7
|
+
data.tar.gz: 561771d6d4081f68fa0342f800fdca04d244872a9a9901aebd141861e53de348d3482140fd74c94d0b9e2fc3080742ff87666467d576f3295ebba711113c2b91
|
data/lib/dredd/dsl/aggregate.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'hashie/mash'
|
2
2
|
require 'statsample'
|
3
|
+
require 'dredd/dsl/predicate'
|
3
4
|
|
4
5
|
|
5
6
|
module Dredd
|
@@ -15,7 +16,7 @@ module Dredd
|
|
15
16
|
(0...collection.size).to_a
|
16
17
|
end
|
17
18
|
|
18
|
-
arr.to_scale.send(@func)
|
19
|
+
@predicate.execute(arr.to_scale.send(@func))
|
19
20
|
end
|
20
21
|
|
21
22
|
|
@@ -23,6 +24,8 @@ module Dredd
|
|
23
24
|
if [:sum, :mean, :min, :max, :size].include?(meth)
|
24
25
|
@func = meth
|
25
26
|
@projection = block
|
27
|
+
@predicate = Predicate.new
|
28
|
+
return @predicate
|
26
29
|
else
|
27
30
|
super
|
28
31
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Dredd
|
2
|
+
module Dsl
|
3
|
+
class Predicate
|
4
|
+
MAP = {
|
5
|
+
:is => :==,
|
6
|
+
:lt => :<,
|
7
|
+
:gt => :>
|
8
|
+
}
|
9
|
+
def execute(val)
|
10
|
+
return val unless @func
|
11
|
+
return val.send(*@func)
|
12
|
+
end
|
13
|
+
|
14
|
+
|
15
|
+
def method_missing(meth, *args, &block)
|
16
|
+
if [:is, :lt, :gt].include?(meth)
|
17
|
+
@func = [MAP[meth], *args]
|
18
|
+
else
|
19
|
+
super
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
data/lib/dredd/version.rb
CHANGED
data/spec/dredd/query_spec.rb
CHANGED
@@ -25,6 +25,9 @@ describe Dredd::Query do
|
|
25
25
|
it "should run aggregations without projection" do
|
26
26
|
q = Dredd::Query.new("all{ foo > 10 }.size")
|
27
27
|
q.execute([{:foo => 1},{:foo => 2}, {:foo => 60}]).must_equal(1)
|
28
|
+
|
29
|
+
q = Dredd::Query.new("(all{ foo > 10 }.size.is 0)")
|
30
|
+
q.execute([{:foo => 1},{:foo => 2}, {:foo => 60}]).must_equal(false)
|
28
31
|
end
|
29
32
|
|
30
33
|
it "should run aggregations on queries" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dredd
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- jondot
|
@@ -110,6 +110,7 @@ files:
|
|
110
110
|
- dredd.gemspec
|
111
111
|
- lib/dredd.rb
|
112
112
|
- lib/dredd/dsl/aggregate.rb
|
113
|
+
- lib/dredd/dsl/predicate.rb
|
113
114
|
- lib/dredd/query.rb
|
114
115
|
- lib/dredd/version.rb
|
115
116
|
- spec/dredd/query_spec.rb
|