Module: Tramway::Core::ExtendableFormsHelpers::Validators
- Defined in:
- app/forms/tramway/core/extendable_forms_helpers/validators.rb
Instance Method Summary collapse
- #inclusion_validator(property_name, validation, value) ⇒ Object
- #make_validates(property_name, validation, value) ⇒ Object
- #presence_validator(property_name, validation, value) ⇒ Object
Instance Method Details
#inclusion_validator(property_name, validation, value) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'app/forms/tramway/core/extendable_forms_helpers/validators.rb', line 27 def inclusion_validator(property_name, validation, value) in_array = validation[1][:in] return if value.in? in_array model.errors.add( property_name, I18n.t( "activerecord.errors.models.#{model.class.name.underscore}.attributes.default.#{validation[0]}", value: value ) ) end |
#make_validates(property_name, validation, value) ⇒ Object
4 5 6 7 8 9 10 11 |
# File 'app/forms/tramway/core/extendable_forms_helpers/validators.rb', line 4 def make_validates(property_name, validation, value) case validation[0].to_s when 'presence' presence_validator property_name, validation, value when 'inclusion' inclusion_validator property_name, validation, value end end |
#presence_validator(property_name, validation, value) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'app/forms/tramway/core/extendable_forms_helpers/validators.rb', line 13 def presence_validator(property_name, validation, value) validator_object = PresenceValidator.new(attributes: :not_blank) return if validation[1] == 'false' return if validation[1] == 'true' && validator_object.send(:valid?, value) model.errors.add( property_name, I18n.t( "activerecord.errors.models.#{model.class.name.underscore}.attributes.default.#{validation[0]}", value: value ) ) end |