Class: ActiveModel::Errors
- Inherits:
-
Object
- Object
- ActiveModel::Errors
- Defined in:
- lib/releaf/rails_ext/validation_error_codes.rb
Instance Method Summary collapse
- #add(attribute, message = nil, options = {}) ⇒ Object
- #normalize_error_code(_attribute, message, options) ⇒ Object
Instance Method Details
#add(attribute, message = nil, options = {}) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/releaf/rails_ext/validation_error_codes.rb', line 13 def add(attribute, = nil, = {}) # build error code from message symbol error_code = normalize_error_code(attribute, , ) = (attribute, , ) if exception = [:strict] exception = ActiveModel::StrictValidationFailed if exception == true raise exception, (attribute, ) end # use customized String subclass with "error_code" attribute self[attribute] << ErrorMessage.new(, error_code, [:data]) end |
#normalize_error_code(_attribute, message, options) ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'lib/releaf/rails_ext/validation_error_codes.rb', line 26 def normalize_error_code(_attribute, , ) if ![:error_code].blank? [:error_code] elsif .class == Symbol else :invalid end end |