Module: Themis::Validation
- Extended by:
- ActiveSupport::Autoload
- Defined in:
- lib/themis/validation.rb,
lib/themis/validation/validator.rb
Overview
Extends other modules to make them be validation modules. Consider it as the “parent module” for all validation modules.
Defined Under Namespace
Classes: Validator
Instance Method Summary collapse
-
#included(base) ⇒ Object
When included in another module: copy validators to another module.
-
#validators ⇒ Array<Validator>
Array validators defined in module.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args) ⇒ Object (private)
Save all calls of validation methods as array of validators
38 39 40 41 42 43 44 |
# File 'lib/themis/validation.rb', line 38 def method_missing(method_name, *args) if method_name.to_s =~ /\Avalidate/ self.validators << Themis::Validation::Validator.new(method_name, args) else super end end |
Instance Method Details
#included(base) ⇒ Object
When included in another module: copy validators to another module. When included in ActiveRecord model: define validators on model.
27 28 29 30 31 32 33 34 35 |
# File 'lib/themis/validation.rb', line 27 def included(base) if base.instance_of?(Module) && base.respond_to?(:validators) base.validators.concat(validators) elsif base.ancestors.include? ::ActiveRecord::Base apply_to_model!(base) else raise "Validation module `#{self.inspect}` can be included only in another validation module or in ActiveRecord model" end end |
#validators ⇒ Array<Validator>
Array validators defined in module.
20 21 22 |
# File 'lib/themis/validation.rb', line 20 def validators @validators ||= [] end |