Sha256: eb7e45135d40a4c1a8f3e3d5b3b461caf58b2c3e0ef9c8b77d547a0b06a09826
Contents?: true
Size: 1.23 KB
Versions: 20
Compression:
Stored size: 1.23 KB
Contents
require 'whyvalidationssuckin96/skippable_validation' require 'whyvalidationssuckin96/attribute_based_validation' module WhyValidationsSuckIn96 # Checks the validity of an attribute against a regular expression. # # @example Default usage # setup_validations do # validates_format_of :username, :with => /[a-z0-9]/i # end class ValidatesFormat < Validation include WhyValidationsSuckIn96::SkippableValidation include WhyValidationsSuckIn96::AttributeBasedValidation DefaultOptions = {:message => "does not match the given format"} # @param [Object] validatable An object to be validated # @param [Hash] options The options to set up the validation with # @option options [Regexp] :with A regular expression to check against def initialize(validatable, options = {}) super raise(ArgumentError, "Regular expression to check against must be given as :with") unless options[:with] end def validate super if attribute_value.to_s =~ options[:with] pass else fail end end end # Validation ValidationBuilder.register_macro :validates_format_of, WhyValidationsSuckIn96::ValidatesFormat end # WhyValidationsSuckIn96
Version data entries
20 entries across 20 versions & 1 rubygems