Permalink
Browse files

Allow any method to be passed as a UUID generator

* Defaults to UUID.new.method(:generate)
* Middleware will use #call and then #to_s the result
  • Loading branch information...
brynary committed Sep 28, 2010
1 parent 278613e commit 63397152494d1d21c1f3a3fb3ac00ee2ef34c35d
@@ -8,12 +8,12 @@ class TransactionIdMiddleware
def initialize(app, options = {})
@app = app
- @uuid_generator = options[:uuid_generator] || UUID.new
+ @uuid_generator = options[:uuid_generator] || UUID.new.method(:generate)
@logger = options[:logger] || Logger.new(STDOUT)
end
def call(env)
- uuid = @uuid_generator.generate
+ uuid = @uuid_generator.call.to_s
@logger.info "[#{self.class.name}] Transaction ID: #{uuid}"
status, headers, body = @app.call(env)
@@ -2,7 +2,7 @@
describe E20::Ops::Middleware::TransactionIdMiddleware do
let(:app) { Proc.new { |env| [200, {}, "OK!"] } }
- let(:uuid) { stub(:generate => "abc123") }
+ let(:uuid) { stub(:call => "abc123") }
let(:logger) { Logger.new(StringIO.new) }
it "is initialized with an app" do

0 comments on commit 6339715

Please sign in to comment.