Method: ActiveRecord::Extensions::CreateAndUpdate#save_with_extension

Defined in:
lib/ar-extensions/create_and_update.rb

#save_with_extension(options = {}) ⇒ Object

:nodoc:



195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
# File 'lib/ar-extensions/create_and_update.rb', line 195

def save_with_extension(options={})#:nodoc:

  #invoke save_with_validation if the argument is not a hash
  return save_without_extension(options) if !options.is_a?(Hash)
  return save_without_extension unless options.any?

  perform_validation = options.delete(:perform_validation)
  raise_exception = options.delete(:raise_exception)

  if (perform_validation.is_a?(FalseClass)) || valid?
    raise ActiveRecord::ReadOnlyRecord if readonly?
    create_or_update(options)
  else
    raise ActiveRecord::RecordInvalid.new(self) if raise_exception
    false
  end
end