url_validator 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +71 -0
- data/init.rb +1 -1
- data/lib/url_validator/version.rb +1 -1
- data/url_validator.gemspec +1 -1
- metadata +5 -5
data/README.markdown
CHANGED
@@ -0,0 +1,71 @@
|
|
1
|
+
# URL Validator #
|
2
|
+
|
3
|
+
---
|
4
|
+
|
5
|
+
URL validator makes possible check URI with different charset like: www.詹姆斯.com . For each setted variable to check, it generates the dynamic method called `variable_normalized`, which return internationalized format of URI. For exmaple `www.詹姆斯.com => www.xn--8ws00zhy3a.com`. This gem is using [addressable](http://github.com/sporkmonger/addressable) gem for internationalizing and beyond regexp for checking valid URI. See in spec kind of valid/invalid URI.
|
6
|
+
|
7
|
+
## Installation ##
|
8
|
+
|
9
|
+
---
|
10
|
+
|
11
|
+
Include the gem in your Gemfile:
|
12
|
+
|
13
|
+
gem "url_validator", "~> 0.0.3"
|
14
|
+
|
15
|
+
Or as a plugin:
|
16
|
+
|
17
|
+
rails plugin install git://github.com/zdenal/url_validator
|
18
|
+
|
19
|
+
## Usage ##
|
20
|
+
|
21
|
+
---
|
22
|
+
|
23
|
+
In your class:
|
24
|
+
|
25
|
+
class User
|
26
|
+
|
27
|
+
attr_accessor :website
|
28
|
+
validates_url :website
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
Then somewhere in code:
|
33
|
+
|
34
|
+
@user.website = 'www.詹姆斯.com'
|
35
|
+
@user2.website = 'website.com'
|
36
|
+
@user.website_normalized # => www.xn--8ws00zhy3a.com
|
37
|
+
@user2.website_normalized # => website.com
|
38
|
+
@user.valid? # => true
|
39
|
+
@user2.valid? # => true
|
40
|
+
@user.website # => http://www.詹姆斯.com
|
41
|
+
@user2.website # => http://website.com
|
42
|
+
|
43
|
+
Url validator automaticly prefill scheme '**http://**' (by schemes options - see below) if is missing in URI.
|
44
|
+
|
45
|
+
## Options ##
|
46
|
+
|
47
|
+
---
|
48
|
+
|
49
|
+
* `:allow_blank => false/true` default = false. The same princip like in others validations.
|
50
|
+
* `:allow_nil => false/true` > default = false. The same princip like in others validations.
|
51
|
+
* `:message => 'Some custom message'` default is: "is not a valid URL". A custom error message.
|
52
|
+
* `:schemes => ['http', 'https',...]` default = ['http', 'https']. Array of URI schemes to validate against. If checked URI missing scheme, then the first scheme of this array is chosen for prefill URI.
|
53
|
+
* `:prefferred_scheme => 'ftp://'` default is the first item from `schemes` array. If setted, then the validator prefill the checked URI with this scheme if missing some scheme.
|
54
|
+
* `:if/:unless => .....` the same like in others validations.
|
55
|
+
|
56
|
+
|
57
|
+
If preffered scheme is 'ftp://' and URI is with some scheme **http://website.com**, then after valid is URI **http://website.com**.
|
58
|
+
|
59
|
+
If preffered scheme is 'ftp://' and URI is without some scheme **website.com**, then after valid is URI **ftp://website.com**.
|
60
|
+
|
61
|
+
For constriction URI schemes, use option `:scheme => ['ftp']`, then **http://website.com** will not valid and **website.com** will valid and prefilled to **ftp://website.com**.
|
62
|
+
|
63
|
+
|
64
|
+
## Tests ##
|
65
|
+
|
66
|
+
---
|
67
|
+
|
68
|
+
You can find more specification for valid/invalid checking URI in spec folder inside tests.
|
69
|
+
|
70
|
+
rake spec # run tests.
|
71
|
+
|
data/init.rb
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
require
|
1
|
+
require File.join(File.dirname(__FILE__), "lib", "url_validator")
|
2
2
|
|
data/url_validator.gemspec
CHANGED
@@ -17,7 +17,7 @@ Gem::Specification.new do |s|
|
|
17
17
|
s.add_development_dependency "rspec"
|
18
18
|
s.add_development_dependency "ruby-debug"
|
19
19
|
s.add_development_dependency "sqlite3"
|
20
|
-
s.add_dependency "rails", "3.0.1"
|
20
|
+
s.add_dependency "rails", "~>3.0.1"
|
21
21
|
s.add_dependency "addressable"
|
22
22
|
|
23
23
|
s.files = `git ls-files`.split("\n")
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: url_validator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 4
|
10
|
+
version: 0.0.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Zdenko Nevrala
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-05-03 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -66,7 +66,7 @@ dependencies:
|
|
66
66
|
requirement: &id004 !ruby/object:Gem::Requirement
|
67
67
|
none: false
|
68
68
|
requirements:
|
69
|
-
- -
|
69
|
+
- - ~>
|
70
70
|
- !ruby/object:Gem::Version
|
71
71
|
hash: 5
|
72
72
|
segments:
|