Module: SuperModel::Validations

Extended by:
ActiveSupport::Concern
Includes:
ActiveModel::Validations
Included in:
Base
Defined in:
lib/supermodel/validations.rb,
lib/supermodel/validations/uniqueness.rb

Defined Under Namespace

Modules: ClassMethods Classes: UniquenessValidator

Instance Method Summary collapse

Instance Method Details

#save_with_validation(options = nil) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/supermodel/validations.rb', line 10

def save_with_validation(options = nil)
  perform_validation = case options
  when Hash
    options[:validate] != false
  when NilClass
    true
  else
    options
  end

  if perform_validation && valid? || !perform_validation
    save_without_validation
    true
  else
    false
  end
rescue InvalidRecord => error
  false
end