Sha256: e000bc6ce3a2d7b6111f51c978e0c8682f8363f28bc9012f387ceaadccb83cc0

Contents?: true

Size: 348 Bytes

Versions: 5

Compression:

Stored size: 348 Bytes

Contents

module FactoryBot
  class << self
    attr_accessor :aliases
  end

  self.aliases = [
    [/(.+)_id/, '\1'],
    [/(.*)/, '\1_id']
  ]

  def self.aliases_for(attribute)
    aliases.map { |(pattern, replace)|
      if pattern.match(attribute.to_s)
        attribute.to_s.sub(pattern, replace).to_sym
      end
    }.compact << attribute
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
factory_bot-6.2.0 lib/factory_bot/aliases.rb
factory_bot-6.1.0 lib/factory_bot/aliases.rb
factory_bot-6.0.2 lib/factory_bot/aliases.rb
factory_bot-6.0.1 lib/factory_bot/aliases.rb
factory_bot-6.0.0 lib/factory_bot/aliases.rb