Module: Currentable::Instance::ClassMethods

Defined in:
lib/currentable/instance.rb

Overview

Methods available on the class

Instance Method Summary collapse

Instance Method Details

#currentObject?

Get the threads value for the current

Returns:

  • (Object, nil)

    The value stored for the current thread.



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.

Parameters:

  • current (Object, nil)

    The value for 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_identifierObject

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