Sha256: 0db470cf75ce164e146a3649463d21fd4f45b7497cce85a4f4983f54caa2bf99

Contents?: true

Size: 351 Bytes

Versions: 6

Compression:

Stored size: 351 Bytes

Contents

module FactoryBot
  class << self
    attr_accessor :aliases
  end

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

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

Version data entries

6 entries across 6 versions & 1 rubygems

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