pukka 0.0.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ # Changelog
2
+
3
+ ## 1.0.0 (13 October 2011)
4
+
5
+ * Email format validator.
@@ -0,0 +1,26 @@
1
+ # Pukka
2
+
3
+ Keep your data Pukka with these custom ActiveModel validators.
4
+
5
+
6
+ ## Quick Start
7
+
8
+ Add `gem 'pukka'` to your Gemfile, run `bundle install`, then just use the validators in your models.
9
+
10
+ For example:
11
+
12
+ class Person < ActiveRecord::Base
13
+ validates :email, :email_format => true
14
+ end
15
+
16
+
17
+ ## Questions, Problems, Feedback
18
+
19
+ Please use the GitHub [issue tracker](https://github.com/airblade/pukka/issues) or email me.
20
+
21
+
22
+ ## Intellectual property
23
+
24
+ Copyright 2011 Andy Stewart (boss@airbladesoftware.com).
25
+
26
+ Released under the MIT licence.
data/Rakefile CHANGED
@@ -1 +1,11 @@
1
- require "bundler/gem_tasks"
1
+ require 'bundler/gem_tasks'
2
+
3
+ require 'rake/testtask'
4
+ require 'rake/rdoctask'
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << 'lib'
8
+ t.libs << 'test'
9
+ t.pattern = 'test/**/*_test.rb'
10
+ t.verbose = false
11
+ end
@@ -1,5 +1,6 @@
1
- require "pukka/version"
1
+ require 'pukka/version'
2
+ require 'pukka/email_format_validator'
2
3
 
3
4
  module Pukka
4
- # Your code goes here...
5
+ #autoload :EmailFormatValidator, 'pukka/email_format_validator'
5
6
  end
@@ -0,0 +1,18 @@
1
+ # Email addresses are notoriously difficult to validate. The only real way is to
2
+ # try to send an email to the address and receive confirmation that it arrived.
3
+ # Clearly this is impractical most of the time.
4
+ #
5
+ # The regexp below is James Watts and Francisco Martin Moreno's one from
6
+ # http://fightingforalostcause.net/misc/2006/compare-email-regex.php
7
+ #
8
+ # There are better ones on that page but they displease Ruby.
9
+ #
10
+ # It's worth reading the discussion there.
11
+ class EmailFormatValidator < ActiveModel::EachValidator
12
+
13
+ def validate_each(record, attribute, value)
14
+ record.errors[attribute] << (options[:message] || 'is not an email address') unless
15
+ value =~ /^([\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+\.)*[\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+@((((([a-z0-9]{1}[a-z0-9\-]{0,62}[a-z0-9]{1})|[a-z])\.)+[a-z]{2,6})|(\d{1,3}\.){3}\d{1,3}(\:\d{1,5})?)$/i
16
+ end
17
+
18
+ end
@@ -1,3 +1,3 @@
1
1
  module Pukka
2
- VERSION = "0.0.1"
2
+ VERSION = '1.0.0'
3
3
  end
@@ -1,15 +1,15 @@
1
1
  # -*- encoding: utf-8 -*-
2
- $:.push File.expand_path("../lib", __FILE__)
3
- require "pukka/version"
2
+ $:.push File.expand_path('../lib', __FILE__)
3
+ require 'pukka/version'
4
4
 
5
5
  Gem::Specification.new do |s|
6
- s.name = "pukka"
6
+ s.name = 'pukka'
7
7
  s.version = Pukka::VERSION
8
- s.authors = ["Andy Stewart"]
9
- s.email = ["boss@airbladesoftware.com"]
10
- s.homepage = ""
8
+ s.authors = ['Andy Stewart']
9
+ s.email = ['boss@airbladesoftware.com']
10
+ s.homepage = 'https://github.com/airblade/pukka'
11
11
  s.summary = 'A handful of custom ActiveModel validators.'
12
- s.description = s.summary
12
+ s.description = 'Keep your data pukka with these custom ActiveModel validators.'
13
13
 
14
14
  s.rubyforge_project = "pukka"
15
15
 
@@ -19,6 +19,5 @@ Gem::Specification.new do |s|
19
19
  s.require_paths = ["lib"]
20
20
 
21
21
  s.add_dependency 'activemodel', '~> 3.0'
22
- s.add_development_dependency 'activesupport', '~> 3.0'
23
22
  s.add_development_dependency 'rake', '0.8.7'
24
23
  end
@@ -0,0 +1,96 @@
1
+ require 'test_helper'
2
+ require 'pukka/email_format_validator'
3
+
4
+ class Thingy
5
+ include ActiveModel::Validations
6
+ attr_accessor :email
7
+ validates :email, :email_format => true
8
+ end
9
+
10
+
11
+ class EmailFormatValidatorTest < Test::Unit::TestCase
12
+
13
+ def setup
14
+ @thingy = Thingy.new
15
+ end
16
+
17
+ def test_valid_formats
18
+ %w[
19
+ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ@letters-in-local.org
20
+ 01234567890@numbers-in-local.net
21
+ &'*+-./=?^_{}~@other-valid-characters-in-local.net
22
+ mixed-1234-in-{+^}-local@sld.net
23
+ a@single-character-in-local.org
24
+ one-character-third-level@a.example.com
25
+ single-character-in-sld@x.org
26
+ local@dash-in-sld.com
27
+ letters-in-sld@123.com
28
+ one-letter-sld@x.org
29
+ uncommon-tld@sld.museum
30
+ uncommon-tld@sld.travel
31
+ uncommon-tld@sld.mobi
32
+ country-code-tld@sld.uk
33
+ country-code-tld@sld.rw
34
+ local@sld.newTLD
35
+ local@sub.domains.com
36
+ ].each do |email|
37
+ @thingy.email = email
38
+ assert @thingy.valid?, "#{email} should be valid"
39
+ end
40
+ end
41
+
42
+ def test_valid_formats_incorrectly_judged_invalid
43
+ %w[
44
+ "quoted"@sld.com
45
+ "\e\s\c\a\p\e\d"@sld.com
46
+ "quoted-at-sign@sld.org"@sld.com
47
+ "escaped\"quote"@sld.com
48
+ "back\slash"@sld.com
49
+ punycode-numbers-in-tld@sld.xn--3e0b707e
50
+ bracketed-IP-instead-of-domain@[127.0.0.1]
51
+ the-total-length@of-an-entire-address-cannot-be-longer-than-two-hundred-and-fifty-four-characters-and-this-address-is-254-characters-exactly-so-it-should-be-valid-and-im-going-to-add-some-more-words-here-to-increase-the-lenght-blah-blah-blah-blah-bla.org
52
+ ].each do |email|
53
+ @thingy.email = email
54
+ assert @thingy.valid?, "#{email} should be valid"
55
+ end
56
+ end
57
+
58
+ def test_invalid_formats
59
+ %w[
60
+ @missing-local.org
61
+ !\ #$%`|@invalid-characters-in-local.org
62
+ (),:;`|@more-invalid-characters-in-local.org
63
+ <>@[]\`|@even-more-invalid-characters-in-local.org
64
+ .local-starts-with-dot@sld.com
65
+ local-ends-with-dot.@sld.com
66
+ two..consecutive-dots@sld.com
67
+ partially."quoted"@sld.com
68
+ missing-sld@.com
69
+ sld-starts-with-dashsh@-sld.com
70
+ sld-ends-with-dash@sld-.com
71
+ invalid-characters-in-sld@!\ "#$%(),/;<>_[]`|.org
72
+ missing-dot-before-tld@com
73
+ missing-tld@sld.
74
+ invalid
75
+ the-total-length@of-an-entire-address-cannot-be-longer-than-two-hundred-and-fifty-four-characters-and-this-address-is-255-characters-exactly-so-it-should-be-invalid-and-im-going-to-add-some-more-words-here-to-increase-the-lenght-blah-blah-blah-blah-bl.org
76
+ missing-at-sign.net
77
+ invalid-ip@127.0.0.1.26
78
+ ].each do |email|
79
+ @thingy.email = email
80
+ assert !@thingy.valid?, "#{email} should not be valid"
81
+ end
82
+ end
83
+
84
+ def test_invalid_formats_incorrectly_judged_valid
85
+ %w[
86
+ the-local-part-is-invalid-if-it-is-longer-than-sixty-four-characters@sld.net
87
+ unbracketed-IP@127.0.0.1
88
+ another-invalid-ip@127.0.0.256
89
+ IP-and-port@127.0.0.1:25
90
+ ].each do |email|
91
+ @thingy.email = email
92
+ assert !@thingy.valid?, "#{email} should not be valid"
93
+ end
94
+ end
95
+
96
+ end
@@ -0,0 +1,2 @@
1
+ require 'test/unit'
2
+ require 'active_model'
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pukka
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
+ - 1
7
8
  - 0
8
9
  - 0
9
- - 1
10
- version: 0.0.1
10
+ version: 1.0.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Andy Stewart
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-10-08 00:00:00 +02:00
18
+ date: 2011-10-13 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -33,25 +33,10 @@ dependencies:
33
33
  version: "3.0"
34
34
  type: :runtime
35
35
  requirement: *id001
36
- - !ruby/object:Gem::Dependency
37
- name: activesupport
38
- prerelease: false
39
- version_requirements: &id002 !ruby/object:Gem::Requirement
40
- none: false
41
- requirements:
42
- - - ~>
43
- - !ruby/object:Gem::Version
44
- hash: 7
45
- segments:
46
- - 3
47
- - 0
48
- version: "3.0"
49
- type: :development
50
- requirement: *id002
51
36
  - !ruby/object:Gem::Dependency
52
37
  name: rake
53
38
  prerelease: false
54
- version_requirements: &id003 !ruby/object:Gem::Requirement
39
+ version_requirements: &id002 !ruby/object:Gem::Requirement
55
40
  none: false
56
41
  requirements:
57
42
  - - "="
@@ -63,8 +48,8 @@ dependencies:
63
48
  - 7
64
49
  version: 0.8.7
65
50
  type: :development
66
- requirement: *id003
67
- description: A handful of custom ActiveModel validators.
51
+ requirement: *id002
52
+ description: Keep your data pukka with these custom ActiveModel validators.
68
53
  email:
69
54
  - boss@airbladesoftware.com
70
55
  executables: []
@@ -75,13 +60,18 @@ extra_rdoc_files: []
75
60
 
76
61
  files:
77
62
  - .gitignore
63
+ - CHANGELOG.md
78
64
  - Gemfile
65
+ - README.md
79
66
  - Rakefile
80
67
  - lib/pukka.rb
68
+ - lib/pukka/email_format_validator.rb
81
69
  - lib/pukka/version.rb
82
70
  - pukka.gemspec
71
+ - test/email_format_validator_test.rb
72
+ - test/test_helper.rb
83
73
  has_rdoc: true
84
- homepage: ""
74
+ homepage: https://github.com/airblade/pukka
85
75
  licenses: []
86
76
 
87
77
  post_install_message:
@@ -114,5 +104,6 @@ rubygems_version: 1.6.2
114
104
  signing_key:
115
105
  specification_version: 3
116
106
  summary: A handful of custom ActiveModel validators.
117
- test_files: []
118
-
107
+ test_files:
108
+ - test/email_format_validator_test.rb
109
+ - test/test_helper.rb