Simplify Current.with_account and .without_account
Co-authored-by: Jeffrey Hardy <jeff@37signals.com>
This commit is contained in:
+4
-12
@@ -12,19 +12,11 @@ class Current < ActiveSupport::CurrentAttributes
|
||||
end
|
||||
end
|
||||
|
||||
def with_account(value)
|
||||
@old_account = self.account
|
||||
self.account = value
|
||||
yield
|
||||
ensure
|
||||
self.account = @old_account
|
||||
def with_account(value, &block)
|
||||
with(account: value, &block)
|
||||
end
|
||||
|
||||
def without_account
|
||||
@old_account = self.account
|
||||
self.account = nil
|
||||
yield
|
||||
ensure
|
||||
self.account = @old_account
|
||||
def without_account(&block)
|
||||
with(account: nil, &block)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user