class Dry::Types::Constructor::Function::MethodCall::PublicCall

@api private
Coercion with a publicly accessible method call

def self.call_interface(method, safe)

Returns:
  • (::Module) -
def self.call_interface(method, safe)
  @interfaces.fetch_or_store([method, safe].hash) do
    ::Module.new do
      if safe
        module_eval(<<~RUBY, __FILE__, __LINE__ + 1)
          def call(input, &block)
            @target.#{method}(input, &block)
          end
        RUBY
      else
        module_eval(<<~RUBY, __FILE__, __LINE__ + 1)
          def call(input, &block)
            @target.#{method}(input)
          rescue NoMethodError, TypeError, ArgumentError => error
            CoercionError.handle(error, &block)
          end
        RUBY
      end
    end
  end
end