Thread.current
このコードの目的は何ですか? Rails アプリケーションで DCI を使用するこの例を見ています。lib/context.rb には、次のようなものがあります。
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
app/contexts のさまざまなコンテキストで使用されます。例:
def bid
in_context do
validator.validate
biddable.create_bid
end
#...
end
ブロックでコードを実行in_context
し、現在のスレッドでキーと値のペアを設定する利点は何ですか?