Module: Coroutine::ActsAsCurrent::ClassMethods
- Defined in:
- lib/acts_as_current/class_methods.rb
Overview
This module defines methods that will be mixed into the class definition when acts_as_current is invoked.
The notation used below assumes the module will be invoked using the :extend method, ensuring the wrapping scope is the class object.
Instance Method Summary collapse
-
#current ⇒ Object
This method returns the reference to the instance defined as current.
-
#current=(instance) ⇒ Object
This method sets the reference to the instance defined as current.
Instance Method Details
#current ⇒ Object
This method returns the reference to the instance defined as current.
14 15 16 |
# File 'lib/acts_as_current/class_methods.rb', line 14 def current Thread.current[acts_as_current_symbol] end |
#current=(instance) ⇒ Object
This method sets the reference to the instance defined as current.
20 21 22 23 24 25 |
# File 'lib/acts_as_current/class_methods.rb', line 20 def current=(instance) unless (instance.is_a?(self) || instance.nil?) raise(ArgumentError, "The method expected an instance of class '#{name}', but instead was given #{instance.inspect}") end Thread.current[acts_as_current_symbol] = instance end |