Class: Sequent::Core::Helpers::DefaultValidators
- Inherits:
-
Object
- Object
- Sequent::Core::Helpers::DefaultValidators
- Defined in:
- lib/sequent/core/helpers/default_validators.rb
Constant Summary collapse
- VALIDATORS =
{ Integer => ->(klass, field) { klass.validates_numericality_of field, only_integer: true, allow_nil: true, allow_blank: true }, Date => ->(klass, field) { klass.validates field, "sequent::Core::Helpers::Date" => true }, DateTime => ->(klass, field) { klass.validates field, "sequent::Core::Helpers::DateTime" => true } }
Class Method Summary collapse
Instance Method Summary collapse
- #add_validations_for(klass, field) ⇒ Object
-
#initialize(type) ⇒ DefaultValidators
constructor
A new instance of DefaultValidators.
Constructor Details
#initialize(type) ⇒ DefaultValidators
Returns a new instance of DefaultValidators.
15 16 17 |
# File 'lib/sequent/core/helpers/default_validators.rb', line 15 def initialize(type) @type = type end |
Class Method Details
.for(type) ⇒ Object
11 12 13 |
# File 'lib/sequent/core/helpers/default_validators.rb', line 11 def self.for(type) new(type) end |
Instance Method Details
#add_validations_for(klass, field) ⇒ Object
19 20 21 22 |
# File 'lib/sequent/core/helpers/default_validators.rb', line 19 def add_validations_for(klass, field) validator = VALIDATORS[@type] validator.call(klass, field) if validator end |