nileshtrivedi-more_validations 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,16 @@
1
+ = MoreValidations
2
+
3
+ Rails gem which adds more validation methods for ActiveRecord columns like email, website, and creditcard
4
+
5
+
6
+ == Install
7
+
8
+ gem install nileshtrivedi-more_validations --source http://gems.github.com
9
+
10
+ == Usage
11
+
12
+ validates_as_email :email
13
+ validates_as_url :website
14
+
15
+ == License
16
+ MIT License
@@ -0,0 +1,14 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'echoe'
4
+
5
+ Echoe.new('more_validations', '0.1.0') do |p|
6
+ p.description = "Add more validation methods for ActiveRecord columns like email, url, and creditcard."
7
+ p.url = "http://github.com/nileshtrivedi/more_validations"
8
+ p.author = "Nilesh Trivedi"
9
+ p.email = "nilesh@latticepurple.com"
10
+ p.ignore_pattern = ["tmp/*", "script/*", "*~"]
11
+ p.development_dependencies = []
12
+ end
13
+
14
+ Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext }
@@ -0,0 +1,44 @@
1
+ module MoreValidations
2
+ # Email regexps shamelessly stolen from restful_authentication
3
+ # This is purposefully imperfect -- it's just a check for bogus input. See
4
+ # http://www.regular-expressions.info/email.html
5
+ RE_EMAIL_NAME = '[\w\.%\+\-]+' # what you actually see in practice
6
+ #RE_EMAIL_NAME = '0-9A-Z!#\$%\&\'\*\+_/=\?^\-`\{|\}~\.' # technically allowed by RFC-2822
7
+ RE_DOMAIN_HEAD = '(?:[A-Z0-9\-]+\.)+'
8
+ RE_DOMAIN_TLD = '(?:[A-Z]{2}|com|org|net|gov|mil|biz|info|mobi|name|aero|jobs|museum)'
9
+ RE_EMAIL_OK = /\A#{RE_EMAIL_NAME}@#{RE_DOMAIN_HEAD}#{RE_DOMAIN_TLD}\z/i
10
+ MSG_EMAIL_BAD = "should be a valid email address."
11
+
12
+ RE_URL_OK = /\A#{RE_DOMAIN_HEAD}#{RE_DOMAIN_TLD}\z/i
13
+ MSG_URL_BAD = "should be a valid URL."
14
+
15
+ def self.included(base)
16
+ base.extend ClassMethods
17
+ end
18
+
19
+ module ClassMethods
20
+ def validates_as_email(*fields)
21
+ fields.each do |field|
22
+ validates_presence_of field
23
+ validates_length_of field, :within => 6..100
24
+ validates_uniqueness_of field, :case_sensitive => false
25
+ validates_format_of field, :with => RE_EMAIL_OK, :message => MSG_EMAIL_BAD
26
+ end
27
+ end
28
+
29
+ def validates_as_url(*fields)
30
+ fields.each do |field|
31
+ validates_presence_of field
32
+ validates_length_of field, :within => 6..100
33
+ validates_uniqueness_of field, :case_sensitive => false
34
+ validates_format_of field, :with => RE_URL_OK, :message => MSG_URL_BAD
35
+ end
36
+ end
37
+
38
+ end
39
+ end
40
+
41
+
42
+ class ActiveRecord::Base
43
+ include MoreValidations
44
+ end
@@ -0,0 +1,31 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{more_validations}
5
+ s.version = "0.1.0"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Nilesh Trivedi"]
9
+ s.date = %q{2009-02-23}
10
+ s.description = %q{Add more validation methods for ActiveRecord columns like email, url, and creditcard.}
11
+ s.email = %q{nilesh@latticepurple.com}
12
+ s.extra_rdoc_files = ["lib/more_validations.rb", "README.rdoc"]
13
+ s.files = ["lib/more_validations.rb", "Rakefile", "README.rdoc", "Manifest", "more_validations.gemspec"]
14
+ s.has_rdoc = true
15
+ s.homepage = %q{http://github.com/nileshtrivedi/more_validations}
16
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "More_validations", "--main", "README.rdoc"]
17
+ s.require_paths = ["lib"]
18
+ s.rubyforge_project = %q{more_validations}
19
+ s.rubygems_version = %q{1.3.1}
20
+ s.summary = %q{Add more validation methods for ActiveRecord columns like email, url, and creditcard.}
21
+
22
+ if s.respond_to? :specification_version then
23
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
24
+ s.specification_version = 2
25
+
26
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
27
+ else
28
+ end
29
+ else
30
+ end
31
+ end
metadata ADDED
@@ -0,0 +1,63 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nileshtrivedi-more_validations
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Nilesh Trivedi
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-02-23 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: Add more validation methods for ActiveRecord columns like email, url, and creditcard.
17
+ email: nilesh@latticepurple.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - lib/more_validations.rb
24
+ - README.rdoc
25
+ files:
26
+ - lib/more_validations.rb
27
+ - Rakefile
28
+ - README.rdoc
29
+ - Manifest
30
+ - more_validations.gemspec
31
+ has_rdoc: true
32
+ homepage: http://github.com/nileshtrivedi/more_validations
33
+ post_install_message:
34
+ rdoc_options:
35
+ - --line-numbers
36
+ - --inline-source
37
+ - --title
38
+ - More_validations
39
+ - --main
40
+ - README.rdoc
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: "0"
48
+ version:
49
+ required_rubygems_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: "1.2"
54
+ version:
55
+ requirements: []
56
+
57
+ rubyforge_project: more_validations
58
+ rubygems_version: 1.2.0
59
+ signing_key:
60
+ specification_version: 2
61
+ summary: Add more validation methods for ActiveRecord columns like email, url, and creditcard.
62
+ test_files: []
63
+