Sha256: 3e78b20542b3240366a9f49990bf19c3c10bf5471fbcb3bab7c33542e26cffe9

Contents?: true

Size: 938 Bytes

Versions: 7

Compression:

Stored size: 938 Bytes

Contents

module FactoryBot
  class Decorator < BasicObject
    undef_method :==

    def initialize(component)
      @component = component
    end

    if ::Gem::Version.new(::RUBY_VERSION) >= ::Gem::Version.new("2.7")
      class_eval(<<~RUBY, __FILE__, __LINE__ + 1)
          def method_missing(...) # rubocop:disable Style/MethodMissingSuper, Style/MissingRespondToMissing
          @component.send(...)
        end

        def send(...)
          __send__(...)
        end
      RUBY
    else
      def method_missing(name, *args, &block) # rubocop:disable Style/MissingRespondToMissing
        @component.send(name, *args, &block)
      end

      def send(symbol, *args, &block)
        __send__(symbol, *args, &block)
      end
    end

    def respond_to_missing?(name, include_private = false)
      @component.respond_to?(name, true) || super
    end

    def self.const_missing(name)
      ::Object.const_get(name)
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
factory_bot-6.4.4 lib/factory_bot/decorator.rb
factory_bot-6.4.3 lib/factory_bot/decorator.rb
factory_bot-6.4.2 lib/factory_bot/decorator.rb
factory_bot-6.4.1 lib/factory_bot/decorator.rb
factory_bot-6.4.0 lib/factory_bot/decorator.rb
factory_bot-6.3.0 lib/factory_bot/decorator.rb
factory_bot-6.2.1 lib/factory_bot/decorator.rb