Class: ThecoreSettings::HexColorValidator
- Inherits:
-
ActiveModel::EachValidator
- Object
- ActiveModel::EachValidator
- ThecoreSettings::HexColorValidator
- Defined in:
- lib/thecore_settings/hex_color_validator.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.matches?(value) ⇒ Boolean
6 7 8 9 |
# File 'lib/thecore_settings/hex_color_validator.rb', line 6 def self.matches?(value) return false unless value /^(?:[0-9a-f]{3})(?:[0-9a-f]{3})?$/i.match(value).nil? ? false : true end |
Instance Method Details
#validate_each(record, attribute, value) ⇒ Object
3 4 5 |
# File 'lib/thecore_settings/hex_color_validator.rb', line 3 def validate_each(record, attribute, value) record.errors[attribute] << ([:message] || I18n.t('admin.settings.color_invalid')) unless value.blank? || self.class.matches?(value) end |