Module: Recliner::Validations
- Extended by:
- ActiveSupport::Concern
- Includes:
- ActiveModel::Validations, ActiveSupport::Callbacks
- Defined in:
- lib/recliner/validations.rb,
lib/recliner/validations/uniqueness.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
-
#errors ⇒ Object
Returns the Errors object that holds all information about attribute error messages.
-
#save_with_validation(perform_validation = true) ⇒ Object
The validation process on save can be skipped by passing false.
-
#save_with_validation! ⇒ Object
Attempts to save the document just like Document#save but will raise a DocumentInvalid exception instead of returning false if the document is not valid.
-
#valid? ⇒ Boolean
Runs all the specified validations and returns true if no errors were added otherwise false.
Instance Method Details
#errors ⇒ Object
Returns the Errors object that holds all information about attribute error messages.
137 138 139 |
# File 'lib/recliner/validations.rb', line 137 def errors @errors ||= Errors.new(self) end |
#save_with_validation(perform_validation = true) ⇒ Object
The validation process on save can be skipped by passing false. The regular Document#save method is replaced with this when the validations module is mixed in, which it is by default.
108 109 110 111 112 113 114 |
# File 'lib/recliner/validations.rb', line 108 def save_with_validation(perform_validation = true) if (perform_validation && valid?) || !perform_validation save_without_validation else false end end |
#save_with_validation! ⇒ Object
Attempts to save the document just like Document#save but will raise a DocumentInvalid exception instead of returning false if the document is not valid.
118 119 120 121 122 123 124 |
# File 'lib/recliner/validations.rb', line 118 def save_with_validation! if valid? save_without_validation! else raise DocumentInvalid.new(self) end end |
#valid? ⇒ Boolean
Runs all the specified validations and returns true if no errors were added otherwise false.
127 128 129 130 131 132 133 134 |
# File 'lib/recliner/validations.rb', line 127 def valid? errors.clear @_on_validate = new_record? ? :create : :update _run_validate_callbacks errors.empty? end |