Class: TwirpRails::ErrorHandlingFactory::ClientProxy
- Inherits:
-
Object
- Object
- TwirpRails::ErrorHandlingFactory::ClientProxy
- Defined in:
- lib/twirp_rails/error_handling/error_handling_factory.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#translator_class ⇒ Object
readonly
Returns the value of attribute translator_class.
Instance Method Summary collapse
-
#initialize(client, translator_class) ⇒ ClientProxy
constructor
A new instance of ClientProxy.
-
#method_missing(method, *args) ⇒ Object
rubocop:disable Style/MethodMissingSuper.
- #raise_on_error(twirp_result) ⇒ Object
-
#respond_to_missing?(method, include_all = false) ⇒ Boolean
rubocop:enable Style/MethodMissingSuper.
Constructor Details
#initialize(client, translator_class) ⇒ ClientProxy
Returns a new instance of ClientProxy.
27 28 29 30 |
# File 'lib/twirp_rails/error_handling/error_handling_factory.rb', line 27 def initialize(client, translator_class) @client = client @translator_class = translator_class end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
rubocop:disable Style/MethodMissingSuper
42 43 44 45 46 47 48 49 50 |
# File 'lib/twirp_rails/error_handling/error_handling_factory.rb', line 42 def method_missing(method, *args) if method =~ /!$/ # when we call a bang version of client method - raise exception translated from error method = method[0..-2] raise_on_error client.public_send(method, *args) else client.public_send method, *args end end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
25 26 27 |
# File 'lib/twirp_rails/error_handling/error_handling_factory.rb', line 25 def client @client end |
#translator_class ⇒ Object (readonly)
Returns the value of attribute translator_class.
25 26 27 |
# File 'lib/twirp_rails/error_handling/error_handling_factory.rb', line 25 def translator_class @translator_class end |
Instance Method Details
#raise_on_error(twirp_result) ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/twirp_rails/error_handling/error_handling_factory.rb', line 32 def raise_on_error(twirp_result) if twirp_result.error exception = translator_class.twirp_to_exception(twirp_result.error) raise exception else twirp_result end end |
#respond_to_missing?(method, include_all = false) ⇒ Boolean
rubocop:enable Style/MethodMissingSuper
53 54 55 |
# File 'lib/twirp_rails/error_handling/error_handling_factory.rb', line 53 def respond_to_missing?(method, include_all = false) client.respond_to?(method, include_all) end |