class Dry::Container::Item

Base class to abstract Memoizable and Callable implementations

@api abstract

Attributes

item[R]

@return [Mixed] the item to be solved later

options[R]

@return [Hash] the options to memoize, call or no.

Public Class Methods

new(item, options = {}) click to toggle source

@api abstract

# File lib/dry/container/item.rb, line 17
def initialize(item, options = {})
  @item = item
  @options = {
    call: item.is_a?(::Proc) && item.parameters.empty?
  }.merge(options)
end

Public Instance Methods

call() click to toggle source

@api abstract

# File lib/dry/container/item.rb, line 25
def call
  raise NotImplementedError
end
callable?() click to toggle source

@private

# File lib/dry/container/item.rb, line 35
def callable?
  options[:call]
end
map(func) click to toggle source

Build a new item with transformation applied

@private

# File lib/dry/container/item.rb, line 42
def map(func)
  if callable?
    self.class.new(-> { func.(item.call) }, options)
  else
    self.class.new(func.(item), options)
  end
end
value?() click to toggle source

@private

# File lib/dry/container/item.rb, line 30
def value?
  !callable?
end