Sha256: a5e8ff52eb2e152a20cd661226ec5ad8b5490ef6eecdf63480233c7370ba5546

Contents?: true

Size: 873 Bytes

Versions: 4

Compression:

Stored size: 873 Bytes

Contents

# frozen_string_literal: true

module FactoryBot
  class With
    # An intermediate object to provide some notation combined with <code>method_missing</code>.
    # @example
    #   class Foo
    #     def foo(name = nil)
    #       return FactoryBot::With::Proxy.new(self, __method__) unless name
    #
    #       name
    #     end
    #   end
    #
    #   Foo.new.foo.bar #=> :bar
    class Proxy < BasicObject
      # @param receiver [Object]
      # @param method [Symbol]
      # @param preargs [Array]
      def initialize(receiver, method, *preargs)
        @receiver = receiver
        @method = method
        @preargs = preargs
      end

      # @!visibility private
      def respond_to_missing?(_method_name, _) = true

      def method_missing(method_name, ...)
        @receiver.__send__(@method, *@preargs, method_name, ...)
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
factory_bot-with-0.3.0 lib/factory_bot/with/proxy.rb
factory_bot-with-0.2.1 lib/factory_bot/with/proxy.rb
factory_bot-with-0.2.0 lib/factory_bot/with/proxy.rb
factory_bot-with-0.1.0 lib/factory_bot/with/proxy.rb