Module: Tablesalt::ThreadAccessor::ClassMethods
- Defined in:
- lib/tablesalt/thread_accessor.rb
Instance Method Summary collapse
-
#thread_accessor(method, thread_key, **options) ⇒ Object
private
Defines instance methods and singleton methods to read/write a given key in Thread.current.
-
#thread_reader(method, thread_key, **options) ⇒ Object
private
Defines an instance method and a singleton method to read from a given key in Thread.current.
-
#thread_writer(method, thread_key, **options) ⇒ Object
private
Defines an instance method and a singleton method to write to a given key in Thread.current.
Instance Method Details
#thread_accessor(method, thread_key, **options) ⇒ Object (private)
Defines instance methods and singleton methods to read/write a given key in Thread.current
91 92 93 94 |
# File 'lib/tablesalt/thread_accessor.rb', line 91 def thread_accessor(method, thread_key, **) thread_reader(method, thread_key, **) thread_writer(method, thread_key, **) end |
#thread_reader(method, thread_key, **options) ⇒ Object (private)
Defines an instance method and a singleton method to read from a given key in Thread.current
29 30 31 32 33 34 35 36 37 |
# File 'lib/tablesalt/thread_accessor.rb', line 29 def thread_reader(method, thread_key, **) define_method(method) { Thread.current[thread_key] } define_singleton_method(method) { Thread.current[thread_key] } return unless .fetch(:private, true) private method private_class_method method end |
#thread_writer(method, thread_key, **options) ⇒ Object (private)
Defines an instance method and a singleton method to write to a given key in Thread.current
56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/tablesalt/thread_accessor.rb', line 56 def thread_writer(method, thread_key, **) method_name = "#{method}=" define_method(method_name) { |value| Thread.current[thread_key] = value } define_singleton_method(method_name) { |value| Thread.current[thread_key] = value } return unless .fetch(:private, true) private method_name private_class_method method_name end |