can_has_validations 0.6.3 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/MIT-LICENSE +1 -1
- data/README.md +5 -1
- data/lib/can_has_validations/validators/url_validator.rb +8 -2
- data/lib/can_has_validations/version.rb +1 -1
- metadata +26 -27
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 98d343f6a4e3bded76cac6973926550938ba481bc9357585c3d83fb8427f48e1
|
4
|
+
data.tar.gz: dc5648966508e9db4ff6972475f1df6b813fa9beb7bd5b83192eb5483ad09e08
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4b6bf6510a992f70ffb418010bc05ae0f97ddb181c7d0482c93ff87756abac7024b8c3e9cf32caee7cfefac7a93bf60b0292475732ea9dc3a39a2009196f6893
|
7
|
+
data.tar.gz: 4a157d72a5ec06a71e3e07a93e4f9fa009fedc7e637b4188d7a7aad2aadb3f55b612e94f3eb3a54dcd1581874ae646f001d00efa956e31e2eb65633b5551a276
|
data/MIT-LICENSE
CHANGED
data/README.md
CHANGED
@@ -190,6 +190,10 @@ can be specified; they default to ['http','https'].
|
|
190
190
|
validates :website, url: true
|
191
191
|
validates :secure_url, url: {scheme: 'https'}
|
192
192
|
|
193
|
+
# Dynamic list of schemes. *Must* return an array.
|
194
|
+
validates :git, url: {scheme: :some_method}
|
195
|
+
validates :old_school, url: {scheme: ->(record){ %w(ftp gopher) }}
|
196
|
+
|
193
197
|
# With IDN parsing:
|
194
198
|
require 'addressable/uri'
|
195
199
|
validates :website, url: true
|
@@ -236,4 +240,4 @@ Default messages are as follows:
|
|
236
240
|
|
237
241
|
## Compatibility ##
|
238
242
|
|
239
|
-
|
243
|
+
The current version is tested with Ruby 2.5-2.6 and ActiveModel 5.2-6.0.
|
@@ -7,7 +7,13 @@
|
|
7
7
|
module ActiveModel::Validations
|
8
8
|
class UrlValidator < ActiveModel::EachValidator
|
9
9
|
def validate_each(record, attribute, value)
|
10
|
-
allowed_schemes =
|
10
|
+
allowed_schemes = if options[:scheme].respond_to?(:call)
|
11
|
+
options[:scheme].call(record)
|
12
|
+
elsif options[:scheme].is_a?(Symbol)
|
13
|
+
record.send(options[:scheme])
|
14
|
+
else
|
15
|
+
Array.wrap(options[:scheme] || %w(http https))
|
16
|
+
end
|
11
17
|
|
12
18
|
if defined?(Addressable::URI)
|
13
19
|
u = Addressable::URI.parse(value) rescue nil
|
@@ -16,7 +22,7 @@ module ActiveModel::Validations
|
|
16
22
|
u2 = u = URI.parse(value) rescue nil
|
17
23
|
end
|
18
24
|
if !u || !u2 || u.relative? || allowed_schemes.exclude?(u.scheme)
|
19
|
-
record.errors.add(attribute, :invalid_url, options.merge(value: value))
|
25
|
+
record.errors.add(attribute, :invalid_url, options.merge(value: value, scheme: allowed_schemes))
|
20
26
|
end
|
21
27
|
end
|
22
28
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: can_has_validations
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- thomas morgan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-04-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -16,20 +16,20 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '5.0'
|
20
20
|
- - "<"
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: '6'
|
22
|
+
version: '6.1'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
26
26
|
requirements:
|
27
27
|
- - ">="
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: '
|
29
|
+
version: '5.0'
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: '6'
|
32
|
+
version: '6.1'
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
34
|
name: sqlite3
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -44,7 +44,7 @@ dependencies:
|
|
44
44
|
- - ">="
|
45
45
|
- !ruby/object:Gem::Version
|
46
46
|
version: '0'
|
47
|
-
description: Assorted Rails
|
47
|
+
description: Assorted Rails 5.x-6.x validators.
|
48
48
|
email:
|
49
49
|
- tm@iprog.com
|
50
50
|
executables: []
|
@@ -115,40 +115,39 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
115
115
|
- !ruby/object:Gem::Version
|
116
116
|
version: '0'
|
117
117
|
requirements: []
|
118
|
-
|
119
|
-
rubygems_version: 2.7.6
|
118
|
+
rubygems_version: 3.0.3
|
120
119
|
signing_key:
|
121
120
|
specification_version: 4
|
122
|
-
summary: Assorted Rails
|
121
|
+
summary: Assorted Rails 5.x-6.x validators
|
123
122
|
test_files:
|
124
|
-
- test/
|
123
|
+
- test/dummy/app/controllers/application_controller.rb
|
124
|
+
- test/dummy/app/views/layouts/application.html.erb
|
125
125
|
- test/dummy/app/assets/javascripts/application.js
|
126
126
|
- test/dummy/app/assets/stylesheets/application.css
|
127
|
-
- test/dummy/app/controllers/application_controller.rb
|
128
127
|
- test/dummy/app/helpers/application_helper.rb
|
129
|
-
- test/dummy/
|
130
|
-
- test/dummy/config/
|
131
|
-
- test/dummy/config/boot.rb
|
132
|
-
- test/dummy/config/database.yml
|
133
|
-
- test/dummy/config/environment.rb
|
134
|
-
- test/dummy/config/environments/development.rb
|
128
|
+
- test/dummy/config/routes.rb
|
129
|
+
- test/dummy/config/locales/en.yml
|
135
130
|
- test/dummy/config/environments/production.rb
|
131
|
+
- test/dummy/config/environments/development.rb
|
136
132
|
- test/dummy/config/environments/test.rb
|
133
|
+
- test/dummy/config/environment.rb
|
134
|
+
- test/dummy/config/application.rb
|
135
|
+
- test/dummy/config/database.yml
|
136
|
+
- test/dummy/config/boot.rb
|
137
137
|
- test/dummy/config/initializers/backtrace_silencers.rb
|
138
|
-
- test/dummy/config/initializers/inflections.rb
|
139
138
|
- test/dummy/config/initializers/mime_types.rb
|
140
|
-
- test/dummy/config/initializers/secret_token.rb
|
141
139
|
- test/dummy/config/initializers/session_store.rb
|
142
140
|
- test/dummy/config/initializers/wrap_parameters.rb
|
143
|
-
- test/dummy/config/
|
144
|
-
- test/dummy/config/
|
141
|
+
- test/dummy/config/initializers/secret_token.rb
|
142
|
+
- test/dummy/config/initializers/inflections.rb
|
145
143
|
- test/dummy/config.ru
|
146
|
-
- test/dummy/
|
147
|
-
- test/dummy/
|
144
|
+
- test/dummy/script/rails
|
145
|
+
- test/dummy/Rakefile
|
146
|
+
- test/dummy/public/favicon.ico
|
148
147
|
- test/dummy/public/422.html
|
149
148
|
- test/dummy/public/500.html
|
150
|
-
- test/dummy/public/
|
151
|
-
- test/dummy/
|
149
|
+
- test/dummy/public/404.html
|
150
|
+
- test/dummy/log/test.log
|
152
151
|
- test/dummy/README.rdoc
|
153
|
-
- test/
|
152
|
+
- test/can_has_validations_test.rb
|
154
153
|
- test/test_helper.rb
|