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
344 B
Ruby
Raw Permalink 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'],
[/(.*)/, '\1_id']
2008-07-30 15:47:12 -04:00
]
2012-05-05 02:31:31 -04:00
def self.aliases_for(attribute)
aliases.map { |(pattern, replace)|
if pattern.match?(attribute)
2008-07-30 15:47:12 -04:00
attribute.to_s.sub(pattern, replace).to_sym
end
}.compact << attribute
2008-07-30 15:47:12 -04:00
end
end