Sha256: d53a8e1f58c5f0ae5605786138770bb63425a5efdf226b817008b27e4cc5f9c4

Contents?: true

Size: 352 Bytes

Versions: 9

Compression:

Stored size: 352 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

9 entries across 9 versions & 1 rubygems

Version Path
factory_bot-5.2.0 lib/factory_bot/aliases.rb
factory_bot-5.1.2 lib/factory_bot/aliases.rb
factory_bot-5.1.1 lib/factory_bot/aliases.rb
factory_bot-5.1.0 lib/factory_bot/aliases.rb
factory_bot-5.0.2 lib/factory_bot/aliases.rb
factory_bot-5.0.1 lib/factory_bot/aliases.rb
factory_bot-5.0.0 lib/factory_bot/aliases.rb
factory_bot-5.0.0.rc2 lib/factory_bot/aliases.rb
factory_bot-5.0.0.rc1 lib/factory_bot/aliases.rb