Class: Dredd::Dsl::Aggregate
- Inherits:
-
Object
- Object
- Dredd::Dsl::Aggregate
show all
- Defined in:
- lib/dredd/dsl/aggregate.rb
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &block) ⇒ Object
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/dredd/dsl/aggregate.rb', line 23
def method_missing(meth, *args, &block)
if [:sum, :mean, :min, :max, :size].include?(meth)
@func = meth
@projection = block
@predicate = Predicate.new
return @predicate
else
super
end
end
|
Instance Method Details
#execute(collection) ⇒ Object
9
10
11
12
13
14
15
16
17
18
19
20
|
# File 'lib/dredd/dsl/aggregate.rb', line 9
def execute(collection)
return collection unless @func
arr = if @projection
collection.map{|k| Hashie::Mash.new(k) }
.map{|k| k.instance_eval(&@projection) }
else
(0...collection.size).to_a
end
@predicate.execute(arr.to_scale.send(@func))
end
|