judge 3.0.0 → 3.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/config/manifest.js +1 -0
- data/lib/judge/config.rb +9 -0
- data/lib/judge/controller.rb +2 -4
- data/lib/judge/validator_collection.rb +23 -1
- data/lib/judge/version.rb +1 -1
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dca4cf9efce355af38a266acbebedbf4e9a248bc
|
4
|
+
data.tar.gz: 8d7c349e62de4f849f624a4ad752c15ca5ea4697
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a86cf16382daebc3d30cb73b27505f388d48dda9129c9e599c626d2672b89df8ba1bb9839562951dd6015e943a1ddb2f77ae597308cef7162862b9ad0a8b42a7
|
7
|
+
data.tar.gz: a7bf16c54d06e2546a7dbc7b4b069e37fdcfcaf3a555812e07bf7ea9fa64799dad5cc438994d562046e4205444fa717a247a850a4510cb272ce57029fb679afb
|
@@ -0,0 +1 @@
|
|
1
|
+
//= link javascripts/judge.js
|
data/lib/judge/config.rb
CHANGED
@@ -6,6 +6,7 @@ module Judge
|
|
6
6
|
|
7
7
|
@@exposed = {}
|
8
8
|
@@ignore_unsupported_validators = false
|
9
|
+
@@use_association_name_for_validations = false
|
9
10
|
|
10
11
|
def expose(klass, *attributes)
|
11
12
|
attrs = (@@exposed[klass.name] ||= [])
|
@@ -36,6 +37,14 @@ module Judge
|
|
36
37
|
def ignore_unsupported_validators?
|
37
38
|
@@ignore_unsupported_validators
|
38
39
|
end
|
40
|
+
|
41
|
+
def use_association_name_for_validations(status)
|
42
|
+
@@use_association_name_for_validations = status
|
43
|
+
end
|
44
|
+
|
45
|
+
def use_association_name_for_validations?
|
46
|
+
@@use_association_name_for_validations
|
47
|
+
end
|
39
48
|
end
|
40
49
|
|
41
50
|
def self.config
|
data/lib/judge/controller.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'uri'
|
2
|
-
|
3
1
|
module Judge
|
4
2
|
module Controller
|
5
3
|
|
@@ -41,9 +39,9 @@ module Judge
|
|
41
39
|
params = params.dup.keep_if {|k| REQUIRED_PARAMS.include?(k) || (k == 'original_value' && params[:kind] == 'uniqueness')}
|
42
40
|
params[:klass] = find_klass(params[:klass]) if params[:klass]
|
43
41
|
params[:attribute] = params[:attribute].to_sym if params[:attribute]
|
44
|
-
params[:value] =
|
42
|
+
params[:value] = CGI::unescape(params[:value]) if params[:value]
|
45
43
|
params[:kind] = params[:kind].to_sym if params[:kind]
|
46
|
-
params[:original_value] =
|
44
|
+
params[:original_value] = CGI::unescape(params[:original_value]) if params[:original_value]
|
47
45
|
params
|
48
46
|
end
|
49
47
|
|
@@ -33,7 +33,23 @@ module Judge
|
|
33
33
|
# unsupported by Judge
|
34
34
|
# if it's a confirmation field, an AM::V like class is added to handle the confirmation validations
|
35
35
|
def amvs
|
36
|
-
|
36
|
+
method_to_search = method
|
37
|
+
|
38
|
+
if Judge.config.use_association_name_for_validations?
|
39
|
+
# since the method that gets passed in here for associations comes in the form of the generated form attribute
|
40
|
+
# i.e. :wine_id or :acclaim_ids
|
41
|
+
# object.class.validators_on(:wine_id) will fail if the active model validation is on the association directly
|
42
|
+
# this ensures that validations defined as 'validates :wine, presence: true' still get applied
|
43
|
+
# and client side error messages get generated
|
44
|
+
regex_for_assocations = /_id|_ids/
|
45
|
+
if method.to_s =~ regex_for_assocations
|
46
|
+
parsed_method = method.to_s.gsub(regex_for_assocations, '');
|
47
|
+
reflection = find_association_reflection(parsed_method)
|
48
|
+
method_to_search = reflection.name if reflection
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
amvs = object.class.validators_on(method_to_search)
|
37
53
|
amvs = amvs.reject { |amv| reject?(amv) || amv.class.name['ConfirmationValidator'] }
|
38
54
|
amvs = amvs.reject { |amv| unsupported_options?(amv) && reject?(amv) != false } if Judge.config.ignore_unsupported_validators?
|
39
55
|
amvs << Judge::ConfirmationValidator.new(object, method) if is_confirmation?
|
@@ -41,6 +57,12 @@ module Judge
|
|
41
57
|
amvs
|
42
58
|
end
|
43
59
|
|
60
|
+
def find_association_reflection(association)
|
61
|
+
if object.class.respond_to?(:reflect_on_association)
|
62
|
+
object.class.reflect_on_association(association) || object.class.reflect_on_association(association.pluralize)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
44
66
|
def unsupported_options?(amv)
|
45
67
|
unsupported = !(amv.options.keys & UNSUPPORTED_OPTIONS).empty?
|
46
68
|
return false unless unsupported
|
data/lib/judge/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: judge
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joe Corcoran
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-02-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 4.0.1
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 4.0.1
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec-extra-formatters
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -116,6 +116,7 @@ extra_rdoc_files: []
|
|
116
116
|
files:
|
117
117
|
- LICENSE.txt
|
118
118
|
- README.md
|
119
|
+
- app/assets/config/manifest.js
|
119
120
|
- app/assets/javascripts/judge.js
|
120
121
|
- app/controllers/judge/validations_controller.rb
|
121
122
|
- config/routes.rb
|
@@ -158,7 +159,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
158
159
|
version: '0'
|
159
160
|
requirements: []
|
160
161
|
rubyforge_project:
|
161
|
-
rubygems_version: 2.
|
162
|
+
rubygems_version: 2.5.2.3
|
162
163
|
signing_key:
|
163
164
|
specification_version: 4
|
164
165
|
summary: Client side validation for Rails
|