aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/dynamic_finder_match.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/lib/active_record/dynamic_finder_match.rb')
-rw-r--r--activerecord/lib/active_record/dynamic_finder_match.rb12
1 files changed, 12 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/dynamic_finder_match.rb b/activerecord/lib/active_record/dynamic_finder_match.rb
index b309df9b1b..80b17a27df 100644
--- a/activerecord/lib/active_record/dynamic_finder_match.rb
+++ b/activerecord/lib/active_record/dynamic_finder_match.rb
@@ -18,6 +18,10 @@ module ActiveRecord
when /^find_by_([_a-zA-Z]\w*)\!$/
bang = true
names = $1
+ when /^find_or_create_by_([_a-zA-Z]\w*)\!$/
+ bang = true
+ instantiator = :create
+ names = $1
when /^find_or_(initialize|create)_by_([_a-zA-Z]\w*)$/
instantiator = $1 == 'initialize' ? :new : :create
names = $2
@@ -52,5 +56,13 @@ module ActiveRecord
def bang?
@bang
end
+
+ def save_record?
+ @instantiator == :create
+ end
+
+ def save_method
+ bang? ? :save! : :save
+ end
end
end