Sha256: 6ee24a476340c292dfb7f29f322c192999272abf8c7066b20795c34e7a7bce84

Contents?: true

Size: 608 Bytes

Versions: 16

Compression:

Stored size: 608 Bytes

Contents

module FactoryBot
  # @api private
  class Enum
    def initialize(attribute_name, values = nil)
      @attribute_name = attribute_name
      @values = values
    end

    def build_traits(klass)
      enum_values(klass).map do |trait_name, value|
        build_trait(trait_name, @attribute_name, value || trait_name)
      end
    end

    private

    def enum_values(klass)
      @values || klass.send(@attribute_name.to_s.pluralize)
    end

    def build_trait(trait_name, attribute_name, value)
      Trait.new(trait_name) do
        add_attribute(attribute_name) { value }
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 2 rubygems

Version Path
factory_bot-6.5.0 lib/factory_bot/enum.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/factory_bot-6.4.6/lib/factory_bot/enum.rb
factory_bot-6.4.6 lib/factory_bot/enum.rb
factory_bot-6.4.5 lib/factory_bot/enum.rb
factory_bot-6.4.4 lib/factory_bot/enum.rb
factory_bot-6.4.3 lib/factory_bot/enum.rb
factory_bot-6.4.2 lib/factory_bot/enum.rb
factory_bot-6.4.1 lib/factory_bot/enum.rb
factory_bot-6.4.0 lib/factory_bot/enum.rb
factory_bot-6.3.0 lib/factory_bot/enum.rb
factory_bot-6.2.1 lib/factory_bot/enum.rb
factory_bot-6.2.0 lib/factory_bot/enum.rb
factory_bot-6.1.0 lib/factory_bot/enum.rb
factory_bot-6.0.2 lib/factory_bot/enum.rb
factory_bot-6.0.1 lib/factory_bot/enum.rb
factory_bot-6.0.0 lib/factory_bot/enum.rb