Sha256: 568373adb72092ef919d953d8c4cdee36901720cc67896fd961701b77cca90b1
Contents?: true
Size: 1.03 KB
Versions: 19
Compression:
Stored size: 1.03 KB
Contents
require 'whyvalidationssuckin96/skippable_validation' require 'whyvalidationssuckin96/attribute_based_validation' require 'uri' module WhyValidationsSuckIn96 # Checks whether a given attribute is a valid URL # # @example Default usage # setup_validations do # validates_as_url :website # end # # @example Specifying valid schemes instead of the defaults # setup_validations do # validates_as_url :website, :schemes => %w[ldap mailto] # end class ValidatesUrl < Validation include WhyValidationsSuckIn96::SkippableValidation include WhyValidationsSuckIn96::AttributeBasedValidation DefaultOptions = {:message => "is not a valid URL", :schemes => %w[http https]} def validate super uri = URI.parse(attribute_value) options[:schemes].include?(uri.scheme) ? pass : fail rescue URI::InvalidURIError => e fail end end # Validation ValidationBuilder.register_macro :validates_as_url, WhyValidationsSuckIn96::ValidatesUrl end # WhyValidationsSuckIn96
Version data entries
19 entries across 19 versions & 1 rubygems