extra_validators 1.1 → 1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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
@@ -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)
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.1"
7
+ - 2
8
+ version: "1.2"
9
9
  platform: ruby
10
10
  authors:
11
11
  - "Aur\xC3\xA9lien Malisart"
@@ -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: []
data/init.rb DELETED
@@ -1 +0,0 @@
1
- require 'extra_validators'