Files

Needle::Lifecycle::Singleton

The instantiation pipeline element that enforces the singleton multiplicity.

Public Instance Methods

call( container, point ) click to toggle source

Returns the cached reference, if it has been previously cached. Otherwise, invokes the next element in the pipeline and caches the result. The cached reference is returned.

    # File lib/needle/lifecycle/singleton.rb, line 38
38:       def call( container, point )
39:         unless @is_cached
40:           @mutex.synchronize do
41:             unless @is_cached
42:               @cached = succ.call( container, point )
43:               @is_cached = true
44:             end
45:           end
46:         end
47: 
48:         @cached
49:       end
initialize_element() click to toggle source

Creates the mutex to use and sets the cached reference to nil.

    # File lib/needle/lifecycle/singleton.rb, line 29
29:       def initialize_element
30:         @mutex = QueryableMutex.new
31:         @cached = nil
32:         @is_cached = false
33:       end
reset!() click to toggle source

Resets the cached singleton instance, so that the next time it is requested it is re-constructed.

    # File lib/needle/lifecycle/singleton.rb, line 53
53:       def reset!
54:         @mutex.synchronize do
55:           @cached = nil
56:           @is_cached = false
57:         end
58:       end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.