Module: Validatable

Defined in:
lib/validatable.rb,
lib/validatable/errors.rb,
lib/validatable/macros.rb,
lib/validatable/validatable.rb,
lib/validatable/validations/validates_each.rb,
lib/validatable/validations/validation_base.rb,
lib/validatable/validations/validates_true_for.rb,
lib/validatable/validations/validates_format_of.rb,
lib/validatable/validations/validates_length_of.rb,
lib/validatable/validations/validates_associated.rb,
lib/validatable/validations/validates_presence_of.rb,
lib/validatable/validations/validates_exclusion_of.rb,
lib/validatable/validations/validates_inclusion_of.rb,
lib/validatable/validations/validates_acceptance_of.rb,
lib/validatable/validations/validates_confirmation_of.rb,
lib/validatable/validations/validates_numericality_of.rb

Defined Under Namespace

Modules: ClassMethods, Macros Classes: Errors, ValidatesAcceptanceOf, ValidatesAssociated, ValidatesConfirmationOf, ValidatesEach, ValidatesExclusionOf, ValidatesFormatOf, ValidatesInclusionOf, ValidatesLengthOf, ValidatesNumericalityOf, ValidatesPresenceOf, ValidatesTrueFor, ValidationBase

Constant Summary collapse

Version =
'1.8.4'

Instance Method Summary collapse

Instance Method Details

#errorsObject

call-seq: errors

Returns the Errors object that holds all information about attribute error messages.



13
14
15
# File 'lib/validatable/validatable.rb', line 13

def errors
  @_errors ||= Validatable::Errors.new
end

#valid?Boolean

call-seq: valid?

Returns true if no errors were added otherwise false. Only executes validations that have no :groups option specified

Returns:

  • (Boolean)


5
6
7
8
# File 'lib/validatable/validatable.rb', line 5

def valid?
  validate
  errors.empty?
end

#validateObject



17
18
19
20
21
22
23
24
# File 'lib/validatable/validatable.rb', line 17

def validate
  return true unless errors.empty?

  self.class.all_validations.each do |validation|
    validation.validate self
  end
  errors.empty?
end