Class: TwirpRails::ErrorHandlingFactory

Inherits:
Object
  • Object
show all
Defined in:
lib/twirp_rails/error_handling/error_handling_factory.rb

Defined Under Namespace

Classes: ClientProxy, HandlerProxy

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.translator_classObject (readonly)

Returns the value of attribute translator_class.



59
60
61
# File 'lib/twirp_rails/error_handling/error_handling_factory.rb', line 59

def translator_class
  @translator_class
end

Class Method Details

.enable_handling?Boolean

Returns:

  • (Boolean)


69
70
71
72
73
74
75
76
77
78
79
# File 'lib/twirp_rails/error_handling/error_handling_factory.rb', line 69

def enable_handling?
  if @enable_handling.nil?
    if (@translator_class = TwirpRails.configuration.twirp_exception_translator_class)
      @translator_class = @translator_class.constantize unless @translator_class.is_a?(Class)
      @enable_handling = true
    else
      @enable_handling = false
    end
  end
  @enable_handling
end

.wrap_client(client) ⇒ Object



65
66
67
# File 'lib/twirp_rails/error_handling/error_handling_factory.rb', line 65

def wrap_client(client)
  enable_handling? ? ClientProxy.new(client, translator_class) : client
end

.wrap_handler(handler) ⇒ Object



61
62
63
# File 'lib/twirp_rails/error_handling/error_handling_factory.rb', line 61

def wrap_handler(handler)
  enable_handling? ? HandlerProxy.new(handler, translator_class) : handler
end