judge 2.0.3 → 2.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  [![Build status](https://secure.travis-ci.org/joecorcoran/judge.png?branch=master)](http://travis-ci.org/joecorcoran/judge)
4
4
 
5
+ [![browser support](https://ci.testling.com/joecorcoran/judge.png)](https://ci.testling.com/joecorcoran/judge)
6
+
5
7
  Judge allows easy client side form validation for Rails 3 by porting many `ActiveModel::Validation` features to JavaScript. The most common validations work through JSON strings stored within HTML5 data attributes and are executed purely on the client side. Wherever you need to, Judge provides a simple interface for AJAX validations too.
6
8
 
7
9
  ## Rationale
@@ -1,5 +1,5 @@
1
- // Judge 2.0.3
2
- // (c) 2011-2012 Joe Corcoran
1
+ // Judge 2.0.4
2
+ // (c) 2011-2013 Joe Corcoran
3
3
  // http://raw.github.com/joecorcoran/judge/master/LICENSE.txt
4
4
 
5
5
  // This is judge.js: the JavaScript part of Judge. Judge is a client-side
@@ -14,7 +14,7 @@
14
14
  var judge = root.judge = {},
15
15
  _ = root._;
16
16
 
17
- judge.VERSION = '2.0.3';
17
+ judge.VERSION = '2.0.4';
18
18
 
19
19
  // Trying to be a bit more descriptive than the basic error types allow.
20
20
  var DependencyError = function(message) {
@@ -8,6 +8,7 @@ files = [
8
8
  'html',
9
9
  'form_builder',
10
10
  'each_validator',
11
+ 'validation',
11
12
  'controller'
12
13
  ]
13
14
  files.each { |filename| require "judge/#{filename}" }
@@ -9,8 +9,8 @@ module Judge
9
9
  end
10
10
 
11
11
  def validation(params)
12
- params = normalize_validation_params(params)
13
- if params[:klass] && Judge.config.exposed?(params[:klass], params[:attribute])
12
+ params = normalized_params(params)
13
+ if params_present?(params) && params_exposed?(params)
14
14
  Validation.new(params)
15
15
  else
16
16
  NullValidation.new(params)
@@ -19,12 +19,22 @@ module Judge
19
19
 
20
20
  private
21
21
 
22
- def normalize_validation_params(params)
23
- params.keep_if { |key| %w{klass attribute value kind}.include?(key) }
24
- params[:klass] = find_klass(params[:klass])
25
- params[:attribute] = params[:attribute].to_sym
26
- params[:value] = URI.decode(params[:value])
27
- params[:kind] = params[:kind].to_sym
22
+ REQUIRED_PARAMS = %w{klass attribute value kind}
23
+
24
+ def params_exposed?(params)
25
+ Judge.config.exposed?(params[:klass], params[:attribute])
26
+ end
27
+
28
+ def params_present?(params)
29
+ params.keys == REQUIRED_PARAMS && params.values.all?
30
+ end
31
+
32
+ def normalized_params(params)
33
+ params = params.dup.keep_if { |k| REQUIRED_PARAMS.include?(k) }
34
+ params[:klass] = find_klass(params[:klass]) if params[:klass]
35
+ params[:attribute] = params[:attribute].to_sym if params[:attribute]
36
+ params[:value] = URI.decode(params[:value]) if params[:value]
37
+ params[:kind] = params[:kind].to_sym if params[:kind]
28
38
  params
29
39
  end
30
40
 
File without changes
@@ -1,3 +1,3 @@
1
1
  module Judge
2
- VERSION = "2.0.3"
2
+ VERSION = "2.0.4"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: judge
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.3
4
+ version: 2.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-03-06 00:00:00.000000000 Z
12
+ date: 2013-05-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -131,7 +131,6 @@ extra_rdoc_files: []
131
131
  files:
132
132
  - app/assets/javascripts/judge.js
133
133
  - app/controllers/judge/validations_controller.rb
134
- - app/models/judge/validation.rb
135
134
  - config/routes.rb
136
135
  - lib/generators/judge/install/install_generator.rb
137
136
  - lib/judge/config.rb
@@ -142,6 +141,7 @@ files:
142
141
  - lib/judge/html.rb
143
142
  - lib/judge/message_collection.rb
144
143
  - lib/judge/message_config.rb
144
+ - lib/judge/validation.rb
145
145
  - lib/judge/validator.rb
146
146
  - lib/judge/validator_collection.rb
147
147
  - lib/judge/version.rb