Class: Dry::Types::Constructor::Function::MethodCall::PublicCall Private

Inherits:
Dry::Types::Constructor::Function::MethodCall show all
Defined in:
lib/dry/types/constructor/function.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Coercion with a publicly accessible method call

Instance Attribute Summary

Attributes inherited from Dry::Types::Constructor::Function::MethodCall

#name, #target

Attributes inherited from Dry::Types::Constructor::Function

#fn

Class Method Summary collapse

Methods inherited from Dry::Types::Constructor::Function::MethodCall

[], call_class, #initialize, #to_ast

Methods inherited from Dry::Types::Constructor::Function

#<<, #>>, [], #arity, #call, #initialize, #to_ast, #wrapper?, yields_block?

Constructor Details

This class inherits a constructor from Dry::Types::Constructor::Function::MethodCall

Class Method Details

.call_interface(method, safe) ⇒ ::Module

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Choose or build the interface

Returns:

  • (::Module)


59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/dry/types/constructor/function.rb', line 59

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)              # def call(input, &block)
            @target.#{method}(input, &block)   #   @target.coerve(input, &block)
          end                                  # end
        RUBY
      else
        module_eval(<<~RUBY, __FILE__, __LINE__ + 1)
          def call(input, &block)                                        # def call(input, &block)
            @target.#{method}(input)                                     #   @target.coerce(input)
          rescue ::NoMethodError, ::TypeError, ::ArgumentError => error  # rescue ::NoMethodError, ::TypeError, ::ArgumentError => error
            CoercionError.handle(error, &block)                          #   CoercionError.handle(error, &block)
          end                                                            # end
        RUBY
      end
    end
  end
end