Skip to content

Instantly share code, notes, and snippets.

@marugoshi
marugoshi / url.rb
Created February 9, 2012 06:30
Custom url validation for Rails3
# -*- coding: utf-8 -*-
class UrlValidator < ::ActiveModel::EachValidator
def validate_each(record, attribute, value)
begin
uri = ::Addressable::URI.parse(value)
unless ["http", "https", "ftp"].include?(uri.scheme)
raise ::Addressable::URI::InvalidURIError
end
rescue ::Addressable::URI::InvalidURIError
record.errors[attribute] << "Invalid URL"
@marugoshi
marugoshi / .watchr
Created February 9, 2012 09:51
My .watchr
def run(cmd)
`#{cmd}`
end
def run_spec(file)
unless File.exist?(file)
puts "#{file} does not exist"
return
end