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

Coercion with a publicly accessible method call

@api private

Public Class Methods

call_interface(method, safe) click to toggle source

Choose or build the interface

@return [::Module]

# File lib/dry/types/constructor/function.rb, line 60
            def self.call_interface(method, safe)
              @interfaces.fetch_or_store([method, safe]) 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