Class: RubyJmeter::FallbackContextProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby-jmeter/helpers/fallback_content_proxy.rb

Constant Summary collapse

NON_PROXIED_METHODS =
Set[:object_id, :__send__, :__id__, :==, :equal?, :"!", :"!=", :instance_eval,
:instance_variables, :instance_variable_get, :instance_variable_set,
:remove_instance_variable]
NON_PROXIED_INSTANCE_VARIABLES =
Set[:@__receiver__, :@__fallback__]

Instance Method Summary collapse

Constructor Details

#initialize(receiver, fallback) ⇒ FallbackContextProxy

Returns a new instance of FallbackContextProxy.



18
19
20
21
# File 'lib/ruby-jmeter/helpers/fallback_content_proxy.rb', line 18

def initialize(receiver, fallback)
  @__receiver__ = receiver
  @__fallback__ = fallback
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



38
39
40
# File 'lib/ruby-jmeter/helpers/fallback_content_proxy.rb', line 38

def method_missing(method, *args, &block)
  __proxy_method__(method, *args, &block)
end

Instance Method Details

#__proxy_method__(method, *args, &block) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
# File 'lib/ruby-jmeter/helpers/fallback_content_proxy.rb', line 42

def __proxy_method__(method, *args, &block)
  begin
    @__receiver__.__send__(method.to_sym, *args, &block)
  rescue ::NoMethodError => e
    begin
      @__fallback__.__send__(method.to_sym, *args, &block)
    rescue ::NoMethodError
      raise(e)
    end
  end
end

#idObject



23
24
25
# File 'lib/ruby-jmeter/helpers/fallback_content_proxy.rb', line 23

def id
  @__receiver__.__send__(:id)
end

#instance_variablesObject

Special case to allow proxy instance variables



33
34
35
36
# File 'lib/ruby-jmeter/helpers/fallback_content_proxy.rb', line 33

def instance_variables
  # Ruby 1.8.x returns string names, convert to symbols
  super.map(&:to_sym) - NON_PROXIED_INSTANCE_VARIABLES.to_a
end

#sub(*args, &block) ⇒ Object

Special case due to ‘Kernel#sub`’s existence



28
29
30
# File 'lib/ruby-jmeter/helpers/fallback_content_proxy.rb', line 28

def sub(*args, &block)
  __proxy_method__(:sub, *args, &block)
end