1
0
Fork 0
mirror of https://github.com/thoughtbot/factory_bot.git synced 2022-11-09 11:43:51 -05:00
thoughtbot--factory_bot/lib/factory_bot/aliases.rb

19 lines
352 B
Ruby
Raw Normal View History

module FactoryBot
class << self
2012-05-05 02:31:31 -04:00
attr_accessor :aliases
end
2008-07-30 15:47:12 -04:00
self.aliases = [
[/(.+)_id/, '\1'],
2018-10-07 18:02:54 -04:00
[/(.*)/, '\1_id'],
2008-07-30 15:47:12 -04:00
]
2012-05-05 02:31:31 -04:00
def self.aliases_for(attribute)
2012-05-05 02:59:13 -04:00
aliases.map do |(pattern, replace)|
2008-07-30 15:47:12 -04:00
if pattern.match(attribute.to_s)
attribute.to_s.sub(pattern, replace).to_sym
end
end.compact << attribute
end
end