Module: SimpleValidation
- Defined in:
- lib/simple_validation.rb,
lib/simple_validation/version.rb
Overview
version.rb
Created by Chirantan Mitra on 2012-11-20 Copyright 2012-2015. All rights reserved
See LICENSE for license
Defined Under Namespace
Modules: ClassMethods
Constant Summary collapse
- VERSION =
:nodoc:
'0.2.1'
Class Method Summary collapse
-
.included(base) ⇒ Object
:nodoc:.
Instance Method Summary collapse
-
#add_error(error) ⇒ Object
Adds an error to the errors collection.
-
#add_errors(more_errors) ⇒ Object
Adds an array of errors to the errors collection.
-
#errors ⇒ Object
Returns an array of the current errors.
-
#invalid? ⇒ Boolean
Runs all validations and returns true if the object is invalid.
-
#valid? ⇒ Boolean
Runs all validations and returns true if the object is valid.
-
#validate ⇒ Object
Run all validations associated with the object.
Class Method Details
.included(base) ⇒ Object
:nodoc:
52 53 54 55 56 |
# File 'lib/simple_validation.rb', line 52 def self.included(base) # :nodoc: base.class_eval do base.extend SimpleValidation::ClassMethods end end |
Instance Method Details
#add_error(error) ⇒ Object
Adds an error to the errors collection
102 103 104 |
# File 'lib/simple_validation.rb', line 102 def add_error(error) all_errors << error end |
#add_errors(more_errors) ⇒ Object
Adds an array of errors to the errors collection
107 108 109 |
# File 'lib/simple_validation.rb', line 107 def add_errors(more_errors) all_errors.concat(more_errors) end |
#errors ⇒ Object
Returns an array of the current errors
112 113 114 115 |
# File 'lib/simple_validation.rb', line 112 def errors validate all_errors end |
#invalid? ⇒ Boolean
Runs all validations and returns true if the object is invalid
97 98 99 |
# File 'lib/simple_validation.rb', line 97 def invalid? !valid? end |
#valid? ⇒ Boolean
Runs all validations and returns true if the object is valid
91 92 93 94 |
# File 'lib/simple_validation.rb', line 91 def valid? validate all_errors.empty? end |
#validate ⇒ Object
Run all validations associated with the object
82 83 84 85 86 87 88 |
# File 'lib/simple_validation.rb', line 82 def validate # :nodoc: return if @validated ||= false @validated = true self.class.validation_methods.each do |method_name, conditions| send method_name if conditions.all? { |condition| send condition } end end |