Module: Currentable::Instance::ClassMethods
- Defined in:
- lib/currentable/instance.rb
Overview
Methods available on the class
Instance Method Summary collapse
-
#current ⇒ Object?
Get the threads value for the current.
-
#current=(current) ⇒ Object
Set a current value on the current thread.
-
#current_identifier ⇒ Object
The identifier for the current.
Instance Method Details
#current ⇒ Object?
Get the threads value for the current
48 49 50 |
# File 'lib/currentable/instance.rb', line 48 def current Thread.current[current_identifier] end |
#current=(current) ⇒ Object
Set a current value on the current thread.
37 38 39 40 41 42 |
# File 'lib/currentable/instance.rb', line 37 def current=(current) if !current.nil? && !current.is_a?(self) raise ArgumentError, "#{current} (#{current.class.name}) is not an instance of #{name}" end Thread.current[current_identifier] = current end |
#current_identifier ⇒ Object
The identifier for the current. Used as the thread hash key.
56 57 58 |
# File 'lib/currentable/instance.rb', line 56 def current_identifier "current.#{name}" end |