Class: Bogus::ProxyClass

Inherits:
Module
  • Object
show all
Defined in:
lib/bogus/contracts/proxy_class.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(fake_name, klass, create_recording_proxy) ⇒ ProxyClass

Returns a new instance of ProxyClass.



3
4
5
6
7
8
9
# File 'lib/bogus/contracts/proxy_class.rb', line 3

def initialize(fake_name, klass, create_recording_proxy)
  @fake_name = fake_name
  @klass = klass
  @create_recording_proxy = create_recording_proxy

  @recording_proxy = @create_recording_proxy.call(@klass, @fake_name)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



19
20
21
# File 'lib/bogus/contracts/proxy_class.rb', line 19

def method_missing(name, *args, &block)
  @recording_proxy.__send__(name, *args, &block)
end

Class Method Details

.create(fake_name, klass, create_recording_proxy) ⇒ Object



11
12
# File 'lib/bogus/contracts/proxy_class.rb', line 11

def self.create(fake_name, klass, create_recording_proxy)
end

Instance Method Details

#const_missing(name) ⇒ Object



23
24
25
# File 'lib/bogus/contracts/proxy_class.rb', line 23

def const_missing(name)
  @recording_proxy.__send__(:const_get, name)
end

#new(*args, &block) ⇒ Object



14
15
16
17
# File 'lib/bogus/contracts/proxy_class.rb', line 14

def new(*args, &block)
  instance = @klass.new(*args, &block)
  @create_recording_proxy.call(instance, @fake_name)
end

#respond_to?(name) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/bogus/contracts/proxy_class.rb', line 27

def respond_to?(name)
  @recording_proxy.respond_to?(name)
end