2017-10-20 15:20:28 -04:00
|
|
|
module FactoryBot
|
2008-12-11 15:54:33 -05:00
|
|
|
class << self
|
2012-05-05 02:31:31 -04:00
|
|
|
attr_accessor :aliases
|
2008-12-11 15:54:33 -05:00
|
|
|
end
|
2011-08-13 01:03:12 -04:00
|
|
|
|
2008-07-30 15:47:12 -04:00
|
|
|
self.aliases = [
|
2010-07-26 07:15:22 -04:00
|
|
|
[/(.+)_id/, '\1'],
|
2020-06-05 15:15:18 -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)
|
2020-06-05 15:15:18 -04:00
|
|
|
aliases.map { |(pattern, replace)|
|
2021-09-09 21:43:47 -04:00
|
|
|
if pattern.match?(attribute)
|
2008-07-30 15:47:12 -04:00
|
|
|
attribute.to_s.sub(pattern, replace).to_sym
|
|
|
|
end
|
2020-06-05 15:15:18 -04:00
|
|
|
}.compact << attribute
|
2008-07-30 15:47:12 -04:00
|
|
|
end
|
|
|
|
end
|