Module: Mead::Validations
- Included in:
- Identifier
- Defined in:
- lib/mead/validations.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
- #errors ⇒ Object
- #valid? ⇒ Boolean
- #valid_format? ⇒ Boolean
- #validate ⇒ Object
- #validate_format ⇒ Object
Class Method Details
.included(base) ⇒ Object
3 4 5 |
# File 'lib/mead/validations.rb', line 3 def self.included(base) base.extend ClassMethods end |
Instance Method Details
#errors ⇒ Object
32 33 34 |
# File 'lib/mead/validations.rb', line 32 def errors @errors ||= {} end |
#valid? ⇒ Boolean
21 22 23 24 25 |
# File 'lib/mead/validations.rb', line 21 def valid? validate_format validate errors.nil? or errors.empty? end |
#valid_format? ⇒ Boolean
27 28 29 30 |
# File 'lib/mead/validations.rb', line 27 def valid_format? validate_format errors.nil? or errors.empty? end |
#validate ⇒ Object
7 8 9 10 11 12 |
# File 'lib/mead/validations.rb', line 7 def validate errors.clear self.class.validations.each do |validation| validation.call(self) end end |
#validate_format ⇒ Object
14 15 16 17 18 19 |
# File 'lib/mead/validations.rb', line 14 def validate_format errors.clear self.class.format_validations.each do |validation| validation.call(self) end end |