Class: Karafka::Routing::Proxy
- Inherits:
-
Object
- Object
- Karafka::Routing::Proxy
- Defined in:
- lib/karafka/routing/proxy.rb
Overview
Proxy is used as a translation layer in between the DSL and raw topic and consumer group objects.
Instance Attribute Summary collapse
-
#target ⇒ Object
readonly
Returns the value of attribute target.
Instance Method Summary collapse
-
#initialize(target, defaults = ->(_) {}, &block) ⇒ Proxy
constructor
A new instance of Proxy.
-
#method_missing(method_name) ⇒ Object
Translates the no “=” DSL of routing into elements assignments on target.
-
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
Tells whether or not a given element exists on the target.
Constructor Details
#initialize(target, defaults = ->(_) {}, &block) ⇒ Proxy
Returns a new instance of Proxy.
15 16 17 18 19 |
# File 'lib/karafka/routing/proxy.rb', line 15 def initialize(target, defaults = ->(_) {}, &block) @target = target instance_eval(&block) if block instance_eval(&defaults) if defaults end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name) ⇒ Object
Translates the no “=” DSL of routing into elements assignments on target
23 24 25 26 27 28 29 30 31 |
# File 'lib/karafka/routing/proxy.rb', line 23 def method_missing(method_name, ...) return super unless respond_to_missing?(method_name) if @target.respond_to?(:"#{method_name}=") @target.public_send(:"#{method_name}=", ...) else @target.public_send(method_name, ...) end end |
Instance Attribute Details
#target ⇒ Object (readonly)
Returns the value of attribute target.
8 9 10 |
# File 'lib/karafka/routing/proxy.rb', line 8 def target @target end |
Instance Method Details
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
Tells whether or not a given element exists on the target
36 37 38 39 40 |
# File 'lib/karafka/routing/proxy.rb', line 36 def respond_to_missing?(method_name, include_private = false) @target.respond_to?(:"#{method_name}=", include_private) || @target.respond_to?(method_name, include_private) || super end |