class Dry::Container::Item::Memoizable
Memoizable
class to store and execute item calls
@api public
Attributes
memoize_mutex[R]
@return [Mutex] the stored mutex
Public Class Methods
new(item, options = {})
click to toggle source
Returns a new Memoizable
instance
@param [Mixed] item @param [Hash] options
@raise [Dry::Container::Error]
@return [Dry::Container::Item::Base]
Calls superclass method
Dry::Container::Item::new
# File lib/dry/container/item/memoizable.rb, line 22 def initialize(item, options = {}) super raise_not_supported_error unless callable? @memoize_mutex = ::Mutex.new end
Public Instance Methods
call()
click to toggle source
Returns the result of item call using a syncronized mutex
@return [Dry::Container::Item::Base]
# File lib/dry/container/item/memoizable.rb, line 32 def call memoize_mutex.synchronize do @memoized_item ||= item.call end end
Private Instance Methods
raise_not_supported_error()
click to toggle source
@private
# File lib/dry/container/item/memoizable.rb, line 41 def raise_not_supported_error raise ::Dry::Container::Error, 'Memoize only supported for a block or a proc'.freeze end