Class: Stubborn::ProxyForInstance
- Inherits:
-
Object
- Object
- Stubborn::ProxyForInstance
- Defined in:
- lib/stubborn/proxy_for_instance.rb
Direct Known Subclasses
Instance Method Summary collapse
- #class ⇒ Object
-
#initialize(proxy_target, options = {}) ⇒ ProxyForInstance
constructor
A new instance of ProxyForInstance.
- #method_missing(method_name, *args, &block) ⇒ Object
Constructor Details
#initialize(proxy_target, options = {}) ⇒ ProxyForInstance
Returns a new instance of ProxyForInstance.
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/stubborn/proxy_for_instance.rb', line 9 def initialize(proxy_target, = {}) @proxy_target = proxy_target [:except] = [[:except]].flatten.compact.map{|m| m.to_s} [:only] = [[:only]].flatten.compact.map{|m| m.to_s} = {:class => proxy_target.class}.merge() @label = [:label] @class = [:class] @methods_to_skip = ["respond_to?", "is_a?", "kind_of?", "equal?", "eql?", "==", "==="] + [:except] @only_methods = [:only] @instance_methods = [:instance_methods] end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/stubborn/proxy_for_instance.rb', line 26 def method_missing(method_name, *args, &block) were_we_already_processing_a_missed_stub = Thread.current["inside_missed_stub"] Thread.current["inside_missed_stub"] = true result = begin @proxy_target.send(method_name, *args, &block) rescue => e e end return result if !@only_methods.include?(method_name.to_s) && !@only_methods.empty? || @methods_to_skip.include?(method_name.to_s) || were_we_already_processing_a_missed_stub raise_missed_stub_exception(method_name, args, result) ensure Thread.current["inside_missed_stub"] = false unless were_we_already_processing_a_missed_stub end |
Instance Method Details
#class ⇒ Object
22 23 24 |
# File 'lib/stubborn/proxy_for_instance.rb', line 22 def class @class end |