Module: PDC::Resource::PerThreadRegistry

Included in:
ScopeRegistry
Defined in:
lib/pdc/resource/per_thread_registry.rb

Class Method Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object (protected)

:nodoc:



48
49
50
51
52
53
54
# File 'lib/pdc/resource/per_thread_registry.rb', line 48

def method_missing(name, *args, &block) # :nodoc:
  # Caches the method definition as a singleton method of the receiver.
  #
  # By letting #delegate handle it, we avoid an enclosure that'll capture args.
  singleton_class.delegate name, to: :instance
  send(name, *args, &block)
end

Class Method Details

.extended(object) ⇒ Object



38
39
40
# File 'lib/pdc/resource/per_thread_registry.rb', line 38

def self.extended(object)
  object.instance_variable_set '@per_thread_registry_key', object.name.freeze
end

Instance Method Details

#instanceObject



42
43
44
# File 'lib/pdc/resource/per_thread_registry.rb', line 42

def instance
  Thread.current[@per_thread_registry_key] ||= new
end