class Needle::Lifecycle::Threaded
The instantiation pipeline element that enforces the singleton multiplicity, on a per-thread basis.
Public Instance Methods
call( container, point )
click to toggle source
Returns the cached reference, if it has been previously cached for the current thread. Otherwise, invokes the next element in the pipeline and caches the result. The cached reference is returned.
# File lib/needle/lifecycle/threaded.rb, line 36 def call( container, point ) cache = service_cache name = service_point.fullname unless cache.has_key?( name ) service = succ.call( container, point ) cache[ name ] = service end cache[ name ] end
reset!()
click to toggle source
Resets the cached singleton instance, so that the next time it is requested it is re-constructed. Only the cache for the current thread and service point is reset.
# File lib/needle/lifecycle/threaded.rb, line 51 def reset! cache = service_cache cache.delete service_point.fullname end
service_cache()
click to toggle source
Returns a Hash of threaded services that are cached by the current thread.
# File lib/needle/lifecycle/threaded.rb, line 29 def service_cache Thread.current[ :threaded_services ] ||= Hash.new end