Module: ActiveLayer::Validations::InstanceMethods

Defined in:
lib/active_layer/validations.rb

Instance Method Summary collapse

Instance Method Details

#errorsObject

model validation methods



20
21
22
23
24
25
26
# File 'lib/active_layer/validations.rb', line 20

def errors
  if active_layer_object.respond_to?(:errors)
    active_layer_object.errors
  else
    super
  end
end

#keep_errors(prefix = "") ⇒ Object



29
30
31
32
33
34
# File 'lib/active_layer/validations.rb', line 29

def keep_errors(prefix = "")
  original_errors = errors.dup
  result = yield
  merge_errors(original_errors, prefix)
  result
end

#merge_errors(other_errors, prefix = nil) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/active_layer/validations.rb', line 36

def merge_errors(other_errors, prefix = nil)
  other_errors.each do |child_attribute, message|
    attribute = "#{prefix}#{child_attribute}"
    errors[attribute] << message
    errors[attribute].uniq!
  end
end

#valid?Boolean

Returns:

  • (Boolean)


44
45
46
47
48
49
# File 'lib/active_layer/validations.rb', line 44

def valid?(*)
  _run_validation_callbacks do
    super
    #keep_errors { active_layer_object.valid? }
  end
end