Sha256: db593dac479ef34db37381a86b744b5e65c8591f215b54b85cec4cea513f3fe3

Contents?: true

Size: 633 Bytes

Versions: 6

Compression:

Stored size: 633 Bytes

Contents

module FactoryBot
  # @api private
  class Trait
    attr_reader :name, :definition

    def initialize(name, &block)
      @name = name
      @block = block
      @definition = Definition.new(@name)

      proxy = FactoryBot::DefinitionProxy.new(@definition)
      proxy.instance_eval(&@block) if block_given?
    end

    delegate :add_callback, :declare_attribute, :to_create, :define_trait, :constructor,
             :callbacks, :attributes, to: :@definition

    def names
      [@name]
    end

    def ==(other)
      name == other.name &&
        block == other.block
    end

    protected
    attr_reader :block
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
factory_bot-4.11.1 lib/factory_bot/trait.rb
factory_bot-4.11.0 lib/factory_bot/trait.rb
factory_bot-4.10.0 lib/factory_bot/trait.rb
factory_bot-4.8.2 lib/factory_bot/trait.rb
factory_bot-1.0.1.alpha lib/factory_bot/trait.rb
factory_bot-1.0.0.alpha lib/factory_bot/trait.rb