Module: Musa::Extension::DynamicProxy::DynamicProxyModule
- Included in:
- DynamicProxy
- Defined in:
- lib/musa-dsl/core-ext/dynamic-proxy.rb
Overview
Mixin module providing dynamic proxy behavior.
This module can be included in classes to add proxy capabilities. Requires an @receiver instance variable to be set.
Instance Method Summary collapse
-
#==(object) ⇒ Boolean
Delegates equality check to receiver or uses original.
-
#_eql? ⇒ Object
Preserve original eql? for internal use.
-
#_equalequal ⇒ Object
Preserve original == for internal use.
-
#_instance_of? ⇒ Object
Preserve original instance_of? for internal use.
-
#_is_a? ⇒ Object
Preserve original is_a? for internal use.
-
#_kind_of? ⇒ Object
Preserve original kind_of? for internal use.
-
#eql?(object) ⇒ Boolean
Delegates eql? check to receiver or uses original.
-
#has_receiver? ⇒ Boolean
Checks if the proxy has a receiver assigned.
-
#instance_of?(klass) ⇒ Boolean
Delegates instance_of? check to receiver or uses original.
-
#is_a?(klass) ⇒ Boolean
Delegates is_a? check to receiver or uses original.
-
#kind_of?(klass) ⇒ Boolean
Delegates kind_of? check to receiver or uses original.
-
#method_missing(method_name, *args, **key_args, &block) ⇒ Object
Forwards unknown methods to the receiver.
-
#respond_to_missing?(method_name, include_private) ⇒ Boolean
Declares which methods the proxy responds to.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, **key_args, &block) ⇒ Object
Forwards unknown methods to the receiver.
38 39 40 41 42 43 44 45 46 |
# File 'lib/musa-dsl/core-ext/dynamic-proxy.rb', line 38 def method_missing(method_name, *args, **key_args, &block) raise NoMethodError, "Method '#{method_name}' is unknown because self is a DynamicProxy with undefined receiver" unless @receiver if @receiver.respond_to? method_name @receiver.send method_name, *args, **key_args, &block else super end end |
Instance Method Details
#==(object) ⇒ Boolean
Delegates equality check to receiver or uses original.
102 103 104 |
# File 'lib/musa-dsl/core-ext/dynamic-proxy.rb', line 102 def ==(object) _equalequal(object) || @receiver&.==(object) end |
#_eql? ⇒ Object
Preserve original eql? for internal use
107 |
# File 'lib/musa-dsl/core-ext/dynamic-proxy.rb', line 107 alias _eql? eql? |
#_equalequal ⇒ Object
Preserve original == for internal use
96 |
# File 'lib/musa-dsl/core-ext/dynamic-proxy.rb', line 96 alias _equalequal == |
#_instance_of? ⇒ Object
Preserve original instance_of? for internal use
85 |
# File 'lib/musa-dsl/core-ext/dynamic-proxy.rb', line 85 alias _instance_of? instance_of? |
#_is_a? ⇒ Object
Preserve original is_a? for internal use
63 |
# File 'lib/musa-dsl/core-ext/dynamic-proxy.rb', line 63 alias _is_a? is_a? |
#_kind_of? ⇒ Object
Preserve original kind_of? for internal use
74 |
# File 'lib/musa-dsl/core-ext/dynamic-proxy.rb', line 74 alias _kind_of? kind_of? |
#eql?(object) ⇒ Boolean
Delegates eql? check to receiver or uses original.
113 114 115 |
# File 'lib/musa-dsl/core-ext/dynamic-proxy.rb', line 113 def eql?(object) _eql?(object) || @receiver&.eql?(object) end |
#has_receiver? ⇒ Boolean
Checks if the proxy has a receiver assigned.
58 59 60 |
# File 'lib/musa-dsl/core-ext/dynamic-proxy.rb', line 58 def has_receiver? !@receiver.nil? end |
#instance_of?(klass) ⇒ Boolean
Delegates instance_of? check to receiver or uses original.
91 92 93 |
# File 'lib/musa-dsl/core-ext/dynamic-proxy.rb', line 91 def instance_of?(klass) _instance_of?(klass) || @receiver&.instance_of?(klass) end |
#is_a?(klass) ⇒ Boolean
Delegates is_a? check to receiver or uses original.
69 70 71 |
# File 'lib/musa-dsl/core-ext/dynamic-proxy.rb', line 69 def is_a?(klass) _is_a?(klass) || @receiver&.is_a?(klass) end |
#kind_of?(klass) ⇒ Boolean
Delegates kind_of? check to receiver or uses original.
80 81 82 |
# File 'lib/musa-dsl/core-ext/dynamic-proxy.rb', line 80 def kind_of?(klass) _kind_of?(klass) || @receiver&.is_a?(klass) end |
#respond_to_missing?(method_name, include_private) ⇒ Boolean
Declares which methods the proxy responds to.
51 52 53 |
# File 'lib/musa-dsl/core-ext/dynamic-proxy.rb', line 51 def respond_to_missing?(method_name, include_private) @receiver&.respond_to?(method_name, include_private) || super end |