Module: Rapid::Setting::NestedValidations::ClassMethods

Defined in:
lib/rapid/setting/nested_validations.rb

Instance Method Summary collapse

Instance Method Details

#nested_validation(validation, attribute, options = {}) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/rapid/setting/nested_validations.rb', line 62

def nested_validation validation, attribute, options = {}
  names = attribute.to_s.split('.')
  name = names.pop
  
  if names.empty?
    send "#{validation}_without_nesting", attribute, options
    return
  end
  
  namespace = setting.find_namespace *names
  klass = namespace.instance_class if namespace
  
  if klass.nil?
    raise UnknownSettingError.new(attribute)
  end
  
  klass.send validation, name, options
end

#nested_validations(validation, attributes, options = {}) ⇒ Object



56
57
58
59
60
# File 'lib/rapid/setting/nested_validations.rb', line 56

def nested_validations validation, attributes, options = {}
  attributes.each do |attribute|
    nested_validation validation, attribute, options
  end
end

#validates_exclusion_of_with_nesting(*args) ⇒ Object



26
27
28
29
# File 'lib/rapid/setting/nested_validations.rb', line 26

def validates_exclusion_of_with_nesting *args
  options = args.extract_options!
  nested_validations :validates_exclusion_of, args, options
end

#validates_format_of_with_nesting(*args) ⇒ Object



31
32
33
34
# File 'lib/rapid/setting/nested_validations.rb', line 31

def validates_format_of_with_nesting *args
  options = args.extract_options!
  nested_validations :validates_format_of, args, options
end

#validates_inclusion_of_with_nesting(*args) ⇒ Object



36
37
38
39
# File 'lib/rapid/setting/nested_validations.rb', line 36

def validates_inclusion_of_with_nesting *args
  options = args.extract_options!
  nested_validations :validates_inclusion_of, args, options
end

#validates_length_of_with_nesting(*args) ⇒ Object



41
42
43
44
# File 'lib/rapid/setting/nested_validations.rb', line 41

def validates_length_of_with_nesting *args
  options = args.extract_options!
  nested_validations :validates_length_of, args, options
end

#validates_presence_of_with_nesting(*args) ⇒ Object



46
47
48
49
# File 'lib/rapid/setting/nested_validations.rb', line 46

def validates_presence_of_with_nesting *args
  options = args.extract_options!
  nested_validations :validates_presence_of, args, options
end

#validates_size_of_with_nesting(*args) ⇒ Object



51
52
53
54
# File 'lib/rapid/setting/nested_validations.rb', line 51

def validates_size_of_with_nesting *args
  options = args.extract_options!
  nested_validations :validates_size_of, args, options
end