The instantiation pipeline element that enforces the multiton multiplicity. "Multiton" multiplicity is like singleton multiplicity, except that the guarded instance is unique for each unique set of arguments passed to the multiton.
Methods
Public Instance methods
Returns the cached reference for the given arguments, if it has been previously cached. Otherwise, invokes the next element in the pipeline and caches the result. The cached reference is returned.
[ show source ]
# File lib/needle/lifecycle/multiton.rb, line 40 40: def call( container, point, *args ) 41: unless @is_cached[ args ] 42: @mutex.synchronize do 43: unless @is_cached[ args ] 44: @cached[ args ] = succ.call( container, point, *args ) 45: @is_cached[ args ] = true 46: end 47: end 48: end 49: 50: @cached[ args ] 51: end
Creates the mutex to use and initializes the cache.
[ show source ]
# File lib/needle/lifecycle/multiton.rb, line 31 31: def initialize_element 32: @mutex = QueryableMutex.new 33: @cached = Hash.new 34: @is_cached = Hash.new( false ) 35: end
Resets the caches for this multiton object.
[ show source ]
# File lib/needle/lifecycle/multiton.rb, line 54 54: def reset! 55: @mutex.synchronize do 56: @cached = Hash.new 57: @is_cached = Hash.new( false ) 58: end 59: end