Class: SystemSettings::ListOfDecimalsValidator
- Inherits:
-
ActiveModel::EachValidator
- Object
- ActiveModel::EachValidator
- SystemSettings::ListOfDecimalsValidator
- Defined in:
- app/models/system_settings/list_of_decimals_validator.rb
Constant Summary collapse
- LIST_REGEXP =
/\A[+-]?\d+(?:\.\d+){0,1}(?:; *[+-]?\d+(?:\.\d+){0,1})*\z/.freeze
- SINGLE_REGEXP =
/\A[+-]?\d+(?:\.\d+){0,1}\z/.freeze
Instance Method Summary collapse
Instance Method Details
#validate_each(record, attr_name, value) ⇒ Object
8 9 10 11 12 13 14 15 16 17 |
# File 'app/models/system_settings/list_of_decimals_validator.rb', line 8 def validate_each(record, attr_name, value) came_from_user = :"#{attr_name}_came_from_user?" raw_value = record.read_attribute_before_type_cast(attr_name) if record.respond_to?(came_from_user) && record.public_send(came_from_user) raw_value ||= value raw_value = value if record_attribute_changed_in_place?(record, attr_name) record.errors.add(attr_name, :not_a_list_of_decimals) unless matches_list_of_decimals_regexp?(raw_value) end |