Files
fizzy/app/models/current.rb
T
Mike Dalessio 9446bc18d2 Simplify Current.with_account and .without_account
Co-authored-by: Jeffrey Hardy <jeff@37signals.com>
2025-11-26 12:31:49 -05:00

23 lines
517 B
Ruby

class Current < ActiveSupport::CurrentAttributes
attribute :session, :user, :account
attribute :http_method, :request_id, :user_agent, :ip_address, :referrer
delegate :identity, to: :session, allow_nil: true
def session=(value)
super(value)
if value.present? && account.present?
self.user = identity.users.find_by(account: account)
end
end
def with_account(value, &block)
with(account: value, &block)
end
def without_account(&block)
with(account: nil, &block)
end
end