What is Thread.current
for in this code? I'm looking at this example of using DCI in a Rails application. In lib/context.rb, there's this:
module Context
include ContextAccessor
def context=(ctx)
Thread.current[:context] = ctx
end
def in_context
old_context = self.context
self.context = self
res = yield
self.context = old_context
res
end
end
which is used in the various contexts in app/contexts, e.g.:
def bid
in_context do
validator.validate
biddable.create_bid
end
#...
end
What is the benefit of running the code in the in_context
block and setting a key-value pair on the current thread?