Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

allow :aggregate to pass existing Aggregate object

This allows an duck-type-compatible object to be used instead of the
default Aggregate class.  This may also be useful for aggregating
numbers from multiple map blocks in one rackup config file.

A duck-type-compatible Aggregate could be one that is thread-safe or
counts/combines stats from multiple processes.
  • Loading branch information...
commit cc8a893e50cf02d18a6beebe2f1a4b1dc96db03c 1 parent 7d33288
Eric Wong authored
Showing with 7 additions and 1 deletion.
  1. +1 −1  lib/rack/aggregate/context.rb
  2. +6 −0 spec/context_spec.rb
View
2  lib/rack/aggregate/context.rb
@@ -9,7 +9,7 @@ def initialize(app, options = {}, &blk)
}.merge(options)
@app = app
- @aggregate = ::Aggregate.new
+ @aggregate = options[:aggregate] || ::Aggregate.new
yield self if block_given?
end
View
6 spec/context_spec.rb
@@ -8,6 +8,12 @@
Rack::Aggregate.new(app).should respond_to(:call)
end
+ it 'take an existing Aggregate object' do
+ a = Aggregate.new
+ tmp = Rack::Aggregate.new(app, :aggregate => a)
+ tmp.instance_variable_get(:@aggregate).object_id.should == a.object_id
+ end
+
it 'take an options Hash' do
lambda { Rack::Aggregate.new(app, {}) }.should_not raise_error(ArgumentError)
end
Please sign in to comment.
Something went wrong with that request. Please try again.