Module: Formidable::GroupValidations

Included in:
Elements::ElementList
Defined in:
lib/formidable/validations.rb

Overview

TODO: better name

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.register_validation(klass, method_name) ⇒ Object



54
55
56
57
58
59
60
# File 'lib/formidable/validations.rb', line 54

def self.register_validation(klass, method_name)
  define_method(method_name) do |*args, &block|
    validation = klass.new(self, *args, &block)
    validations << validation
    self
  end
end

Instance Method Details

#before_validateObject



74
75
# File 'lib/formidable/validations.rb', line 74

def before_validate
end

#errorsObject



62
63
64
# File 'lib/formidable/validations.rb', line 62

def errors
  @errors ||= Errors.new
end

#valid?Boolean

Returns:

  • (Boolean)


70
71
72
# File 'lib/formidable/validations.rb', line 70

def valid?
  self.validate
end

#validateObject



77
78
79
80
81
82
83
84
85
86
# File 'lib/formidable/validations.rb', line 77

def validate
  self.errors.clear
  self.before_validate
  self.elements.each do |element|
    unless element.valid?
      errors[element.name] = element.errors
    end
  end
  self.errors.empty?
end

#validationsObject



66
67
68
# File 'lib/formidable/validations.rb', line 66

def validations
  @validations ||= Array.new
end