extra_validators 1.01 → 1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -29,4 +29,5 @@ If you wanna run the tests :
29
29
 
30
30
  rake spec
31
31
 
32
- Copyright (c) 2010 Aurélien Malisart, released under the MIT license
32
+ Copyright (c) 2010 Aurélien Malisart, released under the MIT license, see
33
+ LICENSE for more details.
@@ -1,2 +1,5 @@
1
+ require 'active_model'
1
2
  require 'extra_validators/email_validator'
2
- require 'extra_validators/url_validator'
3
+ require 'extra_validators/url_validator'
4
+
5
+ ActiveModel::Validations.__send__(:include, ExtraValidators)
@@ -0,0 +1,9 @@
1
+ module ExtraValidators
2
+ class EmailValidator < ActiveModel::EachValidator
3
+ def validate_each(record, attribute, value)
4
+ if value !~ /(\A(\s*)\Z)|(\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z)/i
5
+ record.errors.add(attribute, options[:message])
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module ExtraValidators
2
+ class UrlValidator < ActiveModel::EachValidator
3
+ def validate_each(record, attribute, value)
4
+ if value !~ /^(http|https):\/\/[a-z0-9]+([-.]{1}[a-z0-9]+)*.[a-z]{2,5}(:[0-9]+)?(([0-9]{1,5})?\/.*)?$/ix
5
+ record.errors.add(attribute, options[:message])
6
+ end
7
+ end
8
+ end
9
+ end
metadata CHANGED
@@ -4,8 +4,8 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 1
7
- - 1
8
- version: "1.01"
7
+ - 2
8
+ version: "1.2"
9
9
  platform: ruby
10
10
  authors:
11
11
  - "Aur\xC3\xA9lien Malisart"
@@ -13,7 +13,7 @@ autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
15
 
16
- date: 2010-05-15 00:00:00 +02:00
16
+ date: 2010-05-16 00:00:00 +02:00
17
17
  default_executable:
18
18
  dependencies: []
19
19
 
@@ -26,12 +26,13 @@ extensions: []
26
26
  extra_rdoc_files:
27
27
  - README.rdoc
28
28
  files:
29
+ - lib/extra_validators/email_validator.rb
30
+ - lib/extra_validators/url_validator.rb
29
31
  - lib/extra_validators.rb
30
32
  - spec/extra_validators/validations_spec.rb
31
33
  - spec/spec_helper.rb
32
34
  - README.rdoc
33
35
  - Rakefile
34
- - init.rb
35
36
  has_rdoc: true
36
37
  homepage: http://github.com/aurels/extra_validators
37
38
  licenses: []
@@ -54,8 +55,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
54
55
  - !ruby/object:Gem::Version
55
56
  segments:
56
57
  - 1
57
- - 2
58
- version: "1.2"
58
+ - 3
59
+ - 6
60
+ version: 1.3.6
59
61
  requirements: []
60
62
 
61
63
  rubyforge_project:
data/init.rb DELETED
@@ -1 +0,0 @@
1
- require 'extra_validators'