Module: Toolchain::Validations::ClassMethods
- Defined in:
- lib/toolchain/validations.rb
Instance Method Summary collapse
-
#custom_validations ⇒ Array
All the custom validation operations to run.
-
#include_validations(validations) ⇒ Object
Takes a Proc that contains validation logic and applies that to this class.
-
#validate(method) ⇒ Object
Adds the provided method name to the validations array.
-
#validates(*args) ⇒ Object
Adds the provided validator to the validations array for the provided attribute key_path.
-
#validations ⇒ Array
All the standard validation operations to run.
Instance Method Details
#custom_validations ⇒ Array
Returns all the custom validation operations to run.
20 21 22 |
# File 'lib/toolchain/validations.rb', line 20 def custom_validations @custom_validations ||= [] end |
#include_validations(validations) ⇒ Object
Takes a Proc that contains validation logic and applies that to this class.
69 70 71 |
# File 'lib/toolchain/validations.rb', line 69 def include_validations(validations) class_eval(&validations) end |
#validate(method) ⇒ Object
Adds the provided method name to the validations array. This method will be called during validation time and allows you to do program-specific validations.
60 61 62 |
# File 'lib/toolchain/validations.rb', line 60 def validate(method) custom_validations.push(method.to_sym) end |
#validates(*args) ⇒ Object
Adds the provided validator to the validations array for the provided attribute key_path.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/toolchain/validations.rb', line 35 def validates(*args) , key_path = args.pop, args _if = .delete(:if) _unless = .delete(:unless) .each do |key, data| if validator = Helpers.find_validator(key) validations.push( key_path: key_path, validator: validator, data: data, if: _if, unless: _unless ) end end end |
#validations ⇒ Array
Returns all the standard validation operations to run.
14 15 16 |
# File 'lib/toolchain/validations.rb', line 14 def validations @validations ||= [] end |