Sha256: 95eb81652325f4d9d19a88e4469804e4412f030db858c622e8eaf72978a88801
Contents?: true
Size: 1019 Bytes
Versions: 1
Compression:
Stored size: 1019 Bytes
Contents
require 'active_support/core_ext/object/blank' module ValidatesFormattingOf class MissingValidation < StandardError def initialize(method) super("The validation method #{method.to_sym.inspect} has not been defined.") end end module ValidationAddition attr_reader :validations def add(name, regex, message = nil) @validations ||= {} @validations[name.to_sym] = Validation.new(name.to_sym, regex, message) end def find(attribute, opts = {}) method = opts.fetch(:using, attribute) raise MissingValidation.new(method) if missing? method if method.to_sym == :ip_address raise ArgumentError, "[REMOVED] The :ip_address validation for `validates_formatting_of` has been removed since version 0.7.0. Please update your model validations to use :ip_address_v4." end @validations[method.to_sym] end def missing?(name) !exists?(name) end def exists?(name) @validations[name.to_sym].present? end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
validates_formatting_of-0.7.0 | lib/validates_formatting_of/validation_addition.rb |