Sha256: 43d1a76b8615764de5d5ce647616289ea2d4a3f1c18a7e5370b022b8fa8f7f89

Contents?: true

Size: 435 Bytes

Versions: 15

Compression:

Stored size: 435 Bytes

Contents

module ThecoreSettings
  class HexColorValidator < ActiveModel::EachValidator
    def validate_each(record, attribute, value)
      record.errors[attribute] << (options[:message] || I18n.t('admin.settings.color_invalid')) unless value.blank? || self.class.matches?(value)
    end
    def self.matches?(value)
      return false unless value
      /^(?:[0-9a-f]{3})(?:[0-9a-f]{3})?$/i.match(value).nil? ? false : true
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
thecore_settings-3.0.8 lib/thecore_settings/hex_color_validator.rb
thecore_settings-3.0.7 lib/thecore_settings/hex_color_validator.rb
thecore_settings-2.0.9 lib/thecore_settings/hex_color_validator.rb
thecore_settings-3.0.6 lib/thecore_settings/hex_color_validator.rb
thecore_settings-3.0.5 lib/thecore_settings/hex_color_validator.rb
thecore_settings-3.0.4 lib/thecore_settings/hex_color_validator.rb
thecore_settings-3.0.3 lib/thecore_settings/hex_color_validator.rb
thecore_settings-3.0.0 lib/thecore_settings/hex_color_validator.rb
thecore_settings-2.0.8 lib/thecore_settings/hex_color_validator.rb
thecore_settings-2.0.7 lib/thecore_settings/hex_color_validator.rb
thecore_settings-2.0.6 lib/thecore_settings/hex_color_validator.rb
thecore_settings-2.0.5 lib/thecore_settings/hex_color_validator.rb
thecore_settings-2.0.4 lib/thecore_settings/hex_color_validator.rb
thecore_settings-2.0.3 lib/thecore_settings/hex_color_validator.rb
thecore_settings-2.0.2 lib/thecore_settings/hex_color_validator.rb