Sha256: fa03199b2163c8b7bb5cb583d3e2a49db7566ec0a1d17cd9b350e7fe60e8a7fa

Contents?: true

Size: 582 Bytes

Versions: 3

Compression:

Stored size: 582 Bytes

Contents

module FactoryBotVariants
  class VariantAttributes
    def self.map(attributes)
      variants = []

      common_attributes = attributes.delete(:all)

      attributes.each do |attr_name, attr_values|
        singular_attr_name = attr_name.to_s.singularize.to_sym

        attr_values.each_with_index do |attr_value, index|
          variants[index] ||= {}
          variants[index][singular_attr_name] = attr_value
        end
      end

      if common_attributes
        variants.each { |variant| variant.merge!(common_attributes) }
      end

      variants
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
factory_bot_variants-0.3.0 lib/factory_bot_variants/variant_attributes.rb
factory_bot_variants-0.2.0 lib/factory_bot_variants/variant_attributes.rb
factory_bot_variants-0.1.0 lib/factory_bot_variants/variant_attributes.rb