Skip to content
Browse files

Moved #create! method from Validations to Persistence module

  • Loading branch information...
1 parent 3300fde commit 977a489cfad70dfd0a6a01c4ef792cf6ac0c9046 @bogdan bogdan committed Aug 5, 2014
Showing with 12 additions and 15 deletions.
  1. +12 −0 activerecord/lib/active_record/persistence.rb
  2. +0 −15 activerecord/lib/active_record/validations.rb
View
12 activerecord/lib/active_record/persistence.rb
@@ -36,6 +36,18 @@ def create(attributes = nil, &block)
end
end
+ # Creates an object just like Base.create but calls <tt>save!</tt> instead of +save+
+ # so an exception is raised if the record is invalid.
+ def create!(attributes = nil, &block)
+ if attributes.is_a?(Array)
+ attributes.collect { |attr| create!(attr, &block) }
+ else
+ object = new(attributes, &block)
+ object.save!
+ object
+ end
+ end
+
# Given an attributes hash, +instantiate+ returns a new instance of
# the appropriate class. Accepts only keys as strings.
#
View
15 activerecord/lib/active_record/validations.rb
@@ -29,21 +29,6 @@ module Validations
extend ActiveSupport::Concern
include ActiveModel::Validations
- module ClassMethods
- # Creates an object just like Base.create but calls <tt>save!</tt> instead of +save+
- # so an exception is raised if the record is invalid.
- def create!(attributes = nil, &block)
- if attributes.is_a?(Array)
- attributes.collect { |attr| create!(attr, &block) }
- else
- object = new(attributes)
- yield(object) if block_given?
- object.save!
- object
- end
- end
- end
-
# The validation process on save can be skipped by passing <tt>validate: false</tt>.
# The regular Base#save method is replaced with this when the validations
# module is mixed in, which it is by default.

0 comments on commit 977a489

Please sign in to comment.
Something went wrong with that request. Please try again.