Class: DataValidator::BaseValidator
- Inherits:
-
Object
- Object
- DataValidator::BaseValidator
- Defined in:
- lib/validations/base.rb
Direct Known Subclasses
AcceptanceValidator, ConfirmationValidator, FormatValidator, InclusionValidator, LengthValidator, NumericalityValidator, PresenceValidator
Instance Attribute Summary collapse
-
#errors ⇒ Object
Returns the value of attribute errors.
-
#name ⇒ Object
Returns the value of attribute name.
-
#options ⇒ Object
Returns the value of attribute options.
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
- #add_error(error_message_key, message_args = {}) ⇒ Object
- #check_validity! ⇒ Object
-
#initialize(name, value, options, errors) ⇒ BaseValidator
constructor
A new instance of BaseValidator.
- #validate ⇒ Object
Constructor Details
#initialize(name, value, options, errors) ⇒ BaseValidator
Returns a new instance of BaseValidator.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/validations/base.rb', line 9 def initialize(name, value, , errors) raise ArgumentError, 'Options must define' if .blank? case when Hash @options = else @options = {} end @name = name @value = value @errors = errors end |
Instance Attribute Details
#errors ⇒ Object
Returns the value of attribute errors.
7 8 9 |
# File 'lib/validations/base.rb', line 7 def errors @errors end |
#name ⇒ Object
Returns the value of attribute name.
7 8 9 |
# File 'lib/validations/base.rb', line 7 def name @name end |
#options ⇒ Object
Returns the value of attribute options.
7 8 9 |
# File 'lib/validations/base.rb', line 7 def @options end |
#value ⇒ Object
Returns the value of attribute value.
7 8 9 |
# File 'lib/validations/base.rb', line 7 def value @value end |
Instance Method Details
#add_error(error_message_key, message_args = {}) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/validations/base.rb', line 31 def add_error(, = {}) error_subject_key = "datavalidator.errors.subjects.#{name}" error_subject = '' begin error_subject = I18n.t! "datavalidator.errors.subjects.#{name}" rescue error_subject = name.to_s end if errors.key? name errors[name] << "#{error_subject} #{I18n.t("datavalidator.errors.messages.#{.to_s}", )}" else errors[name] = ["#{error_subject} #{I18n.t("datavalidator.errors.messages.#{.to_s}", )}"] end end |
#check_validity! ⇒ Object
24 25 |
# File 'lib/validations/base.rb', line 24 def check_validity! end |
#validate ⇒ Object
27 28 29 |
# File 'lib/validations/base.rb', line 27 def validate raise ArgumentError, 'Validate method is necessary' end |