Class: FactoryBot::With::Proxy

Inherits:
BasicObject
Defined in:
lib/factory_bot/with/proxy.rb

Overview

An intermediate object to provide some notation combined with method_missing.

Examples:

class Example
  def foo(name = nil, ...)
    return FactoryBot::With::Proxy.new(self, __method__) unless name

    name
  end
end

ex = Example.new
ex.foo.bar #=> :bar

Instance Method Summary collapse

Constructor Details

#initialize(receiver, method) ⇒ Proxy

Returns a new instance of Proxy.

Parameters:

  • receiver (Object)
  • method (Symbol)


20
21
22
23
# File 'lib/factory_bot/with/proxy.rb', line 20

def initialize(receiver, method)
  @receiver = receiver
  @method = method
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name) ⇒ Object



28
# File 'lib/factory_bot/with/proxy.rb', line 28

def method_missing(method_name, ...) = @receiver.__send__(@method, method_name, ...)