Sha256: 535b717da2ba83c16c378ab8679aba88e87e1a695272c70cb12a71f28086c03f
Contents?: true
Size: 775 Bytes
Versions: 3
Compression:
Stored size: 775 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 @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
3 entries across 3 versions & 1 rubygems