client_side_validations 4.2.0 → 4.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 74a0ec2fee1f73f4bbb10e8384609c16914c16e9
4
- data.tar.gz: fdc6f78dd60b02930a4bfc876e090785c21f5206
3
+ metadata.gz: 1365fb3dbcb3cc78e1ff81c55ca7bae68562a36a
4
+ data.tar.gz: 929f39e3d25915e36ee0857c28cd366d4ed66a3e
5
5
  SHA512:
6
- metadata.gz: 2c777cc7a0190546e612e7602e5dc578d5e30172d3b0393912ad8d2e5c2d48b36d9e3a5fe9cc5979e5ad3e8dada301d0f0eab51bca923fc8d02f63e3fcef0017
7
- data.tar.gz: 795119c15633fb66e4b6091eb3e4a29698b49791855a64488de8c687f62fb2138924f4f849c2be99ae2cd78e8055f40bc2af3663aa935a9a431ee105ad1962c7
6
+ metadata.gz: 3aa912a26a995bf9863abb7e7b1384c1d071c8301088f7723c9e24b3863b5d8b6f345226874d811c82263ff16f620153155699f9a5ebca7a7331db33256bc801
7
+ data.tar.gz: 7f63fd221eb2699d19ca1a4cabe5be3598fd76973f314137fdcaea9b76f704de3c2a5379fce95cb28dae2d4b3f7b182243942bc9d5b364f3e45de8d8aae8d390
data/HISTORY.md CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  ## Version 4.2
4
4
 
5
+ * [v4.2.1](https://github.com/DavyJonesLocker/client_side_validations/compare/v4.2.0...v4.2.1)
5
6
  * [v4.2.0](https://github.com/DavyJonesLocker/client_side_validations/compare/v3.2.6...v4.2.0)
6
7
 
7
8
  ## Version 3.2
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module ClientSideValidations
2
3
  module ActionView
3
4
  module Helpers
@@ -91,11 +92,12 @@ module ClientSideValidations
91
92
  result[attr[0]] = attr[1][:options]
92
93
  end
93
94
 
94
- if object_opts[0].respond_to?(:client_side_validation_hash)
95
- validation_hash = object_opts[0].client_side_validation_hash(option_hash)
96
- else
97
- validation_hash = {}
98
- end
95
+ validation_hash =
96
+ if object_opts[0].respond_to?(:client_side_validation_hash)
97
+ object_opts[0].client_side_validation_hash(option_hash)
98
+ else
99
+ {}
100
+ end
99
101
 
100
102
  option_hash.each_key do |attr|
101
103
  if validation_hash[attr]
@@ -107,26 +109,26 @@ module ClientSideValidations
107
109
 
108
110
  def client_side_form_settings(object, options, builder)
109
111
  return unless options[:validate]
110
- if options[:id]
111
- var_name = options[:id]
112
- else
113
- var_name =
114
- if object.respond_to?(:persisted?) && object.persisted?
115
- options[:as] ? "edit_#{options[:as]}" : [options[:namespace], dom_id(object, :edit)].compact.join('_'.freeze)
116
- else
117
- options[:as] ? "new_#{options[:as]}" : [options[:namespace], dom_id(object)].compact.join('_'.freeze)
118
- end
119
- end
112
+ var_name =
113
+ if options[:id]
114
+ options[:id]
115
+ elsif object.respond_to?(:persisted?) && object.persisted?
116
+ options[:as] ? "edit_#{options[:as]}" : [options[:namespace], dom_id(object, :edit)].compact.join('_'.freeze)
117
+ else
118
+ options[:as] ? "new_#{options[:as]}" : [options[:namespace], dom_id(object)].compact.join('_'.freeze)
119
+ end
120
+
121
+ number_format =
122
+ if ClientSideValidations::Config.number_format_with_locale && defined?(I18n)
123
+ I18n.t('number.format').slice(:separator, :delimiter)
124
+ else
125
+ { separator: '.', delimiter: ',' }
126
+ end
120
127
 
121
- if ClientSideValidations::Config.number_format_with_locale && defined?(I18n)
122
- number_format = I18n.t('number.format').slice(:separator, :delimiter)
123
- else
124
- number_format = { separator: '.', delimiter: ',' }
125
- end
126
128
  patterns = { numericality: "/^(-|\\+)?(?:\\d+|\\d{1,3}(?:\\#{number_format[:delimiter]}\\d{3})+)(?:\\#{number_format[:separator]}\\d*)?$/" }
127
129
 
128
130
  content_tag(:script) do
129
- "//<![CDATA[\nif(window.ClientSideValidations===undefined)window.ClientSideValidations={};window.ClientSideValidations.disabled_validators=#{ClientSideValidations::Config.disabled_validators.to_json};window.ClientSideValidations.number_format=#{number_format.to_json};if(window.ClientSideValidations.patterns===undefined)window.ClientSideValidations.patterns = {};window.ClientSideValidations.patterns.numericality=#{patterns[:numericality]};#{"if(window.ClientSideValidations.remote_validators_prefix===undefined)window.ClientSideValidations.remote_validators_prefix='#{(ClientSideValidations::Config.root_path).sub(%r{/+\Z}, '')}';" if ClientSideValidations::Config.root_path.present?}if(window.ClientSideValidations.forms===undefined)window.ClientSideValidations.forms={};window.ClientSideValidations.forms['#{var_name}'] = #{builder.client_side_form_settings(options, self).merge(validators: 'validator_hash').to_json};\n//]]>".html_safe
131
+ "//<![CDATA[\nif(window.ClientSideValidations===undefined)window.ClientSideValidations={};window.ClientSideValidations.disabled_validators=#{ClientSideValidations::Config.disabled_validators.to_json};window.ClientSideValidations.number_format=#{number_format.to_json};if(window.ClientSideValidations.patterns===undefined)window.ClientSideValidations.patterns = {};window.ClientSideValidations.patterns.numericality=#{patterns[:numericality]};#{"if(window.ClientSideValidations.remote_validators_prefix===undefined)window.ClientSideValidations.remote_validators_prefix='#{ClientSideValidations::Config.root_path.sub(%r{/+\Z}, '')}';" if ClientSideValidations::Config.root_path.present?}if(window.ClientSideValidations.forms===undefined)window.ClientSideValidations.forms={};window.ClientSideValidations.forms['#{var_name}'] = #{builder.client_side_form_settings(options, self).merge(validators: 'validator_hash').to_json};\n//]]>".html_safe
130
132
  end
131
133
  end
132
134
  end
@@ -28,7 +28,7 @@ module ClientSideValidations
28
28
  return attr_hash if [nil, :block].include?(attr[0])
29
29
 
30
30
  validator_hash = attr[1].each_with_object(Hash.new { |h, k| h[k] = [] }) do |validator, kind_hash|
31
- next unless can_use_for_client_side_validation?(attr[0], validator, force)
31
+ next nil unless can_use_for_client_side_validation?(attr[0], validator, force)
32
32
 
33
33
  client_side_hash = validator.client_side_hash(self, attr[0], extract_force_option(attr[0], force))
34
34
  if client_side_hash
@@ -59,7 +59,7 @@ module ClientSideValidations
59
59
  return false if validator_turned_off?(attr, validator, force)
60
60
 
61
61
  # Yeah yeah, #new_record? is not part of ActiveModel :p
62
- result = ((self.respond_to?(:new_record?) && validator.options[:on] == (self.new_record? ? :create : :update)) || validator.options[:on].nil?)
62
+ result = ((respond_to?(:new_record?) && validator.options[:on] == (new_record? ? :create : :update)) || validator.options[:on].nil?)
63
63
  result &&= validator.kind != :block
64
64
 
65
65
  if validator.options[:if] || validator.options[:unless]
@@ -127,17 +127,14 @@ module ClientSideValidations
127
127
  module EnumerableValidator
128
128
  def client_side_hash(model, attribute, force = nil)
129
129
  options = self.options.dup
130
+
130
131
  if options[:in].respond_to?(:call)
131
- if force
132
- options[:in] = options[:in].call(model)
133
- hash = build_client_side_hash(model, attribute, options)
134
- else
135
- return
136
- end
137
- else
138
- hash = build_client_side_hash(model, attribute, options)
132
+ return unless force
133
+ options[:in] = options[:in].call(model)
139
134
  end
140
135
 
136
+ hash = build_client_side_hash(model, attribute, options)
137
+
141
138
  if hash[:in].is_a?(Range)
142
139
  hash[:range] = hash[:in]
143
140
  hash.delete(:in)
@@ -4,19 +4,13 @@ module ClientSideValidations
4
4
  def client_side_hash(model, attribute, force = nil)
5
5
  options = self.options.dup
6
6
  if options[:with].respond_to?(:call)
7
- if force
8
- options[:with] = options[:with].call(model)
9
- build_client_side_hash(model, attribute, options)
10
- else
11
- return
12
- end
7
+ return unless force
8
+ options[:with] = options[:with].call(model)
9
+ build_client_side_hash(model, attribute, options)
13
10
  elsif options[:without].respond_to?(:call)
14
- if force
15
- options[:without] = options[:without].call(model)
16
- build_client_side_hash(model, attribute, options)
17
- else
18
- return
19
- end
11
+ return unless force
12
+ options[:without] = options[:without].call(model)
13
+ build_client_side_hash(model, attribute, options)
20
14
  else
21
15
  super
22
16
  end
@@ -1,10 +1,10 @@
1
1
  module ClientSideValidations
2
2
  module ActiveModel
3
3
  module Numericality
4
- OPTION_MAP = {}
4
+ @@option_map = {}
5
5
 
6
6
  def self.included(base)
7
- OPTION_MAP.merge!(base::CHECKS.keys.inject({}) { |a, e| a.merge!(e => e) })
7
+ @@option_map.merge!(base::CHECKS.keys.inject({}) { |a, e| a.merge!(e => e) })
8
8
  end
9
9
 
10
10
  def client_side_hash(model, attribute, force = nil)
@@ -18,16 +18,13 @@ module ClientSideValidations
18
18
 
19
19
  hash[:allow_blank] = true if options[:allow_nil] || options[:allow_blank]
20
20
 
21
- OPTION_MAP.each do |option, message_type|
21
+ @@option_map.each do |option, message_type|
22
22
  count = options[option]
23
23
  next unless count
24
24
 
25
25
  if count.respond_to?(:call)
26
- if force
27
- count = count.call(model)
28
- else
29
- next
30
- end
26
+ next unless force
27
+ count = count.call(model)
31
28
  end
32
29
 
33
30
  hash[:messages][option] = model.errors.generate_message(attribute, message_type, options.merge(count: count))
@@ -1,9 +1,13 @@
1
1
  module ClientSideValidations
2
2
  module Generators
3
- ASSETS = []
3
+ @@assets = []
4
4
 
5
5
  def self.register_assets(klass)
6
- ASSETS.push(*klass.assets)
6
+ @@assets.push(*klass.assets)
7
+ end
8
+
9
+ def self.assets
10
+ @@assets
7
11
  end
8
12
  end
9
13
  end
@@ -58,8 +58,8 @@ module ClientSideValidations
58
58
  end
59
59
 
60
60
  class Uniqueness < Base
61
- IGNORE_PARAMS = %w(case_sensitive id scope)
62
- REGISTERED_ORMS = []
61
+ IGNORE_PARAMS = %w(case_sensitive id scope).freeze
62
+ @@registered_orms = []
63
63
  class NotValidatable < StandardError; end
64
64
 
65
65
  def response
@@ -83,7 +83,7 @@ module ClientSideValidations
83
83
  end
84
84
 
85
85
  def self.registered_orms
86
- REGISTERED_ORMS
86
+ @@registered_orms
87
87
  end
88
88
 
89
89
  def registered_orms
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module ClientSideValidations
2
- VERSION = '4.2.0'.freeze
3
+ VERSION = '4.2.1'.freeze
3
4
  end
@@ -9,8 +9,6 @@ module ClientSideValidations
9
9
  end
10
10
  end
11
11
 
12
- private
13
-
14
12
  def self.asset_directory
15
13
  if asset_pipeline_enabled?
16
14
  "app#{Rails.configuration.assets.prefix}/javascripts"
@@ -19,16 +17,8 @@ module ClientSideValidations
19
17
  end
20
18
  end
21
19
 
22
- def asset_directory
23
- CopyAssetsGenerator.asset_directory
24
- end
25
-
26
20
  def self.assets
27
- ASSETS
28
- end
29
-
30
- def assets
31
- CopyAssetsGenerator.assets
21
+ ClientSideValidations::Generators.assets
32
22
  end
33
23
 
34
24
  def self.asset_file_names
@@ -40,15 +30,25 @@ module ClientSideValidations
40
30
  defined?(Sprockets).present?
41
31
  end
42
32
 
43
- def asset_pipeline_enabled?
44
- self.class.asset_pipeline_enabled?
45
- end
46
-
47
33
  def self.installation_message
48
34
  "Copies #{asset_file_names} to #{asset_directory}"
49
35
  end
50
36
 
51
37
  desc installation_message
38
+
39
+ private
40
+
41
+ def asset_directory
42
+ CopyAssetsGenerator.asset_directory
43
+ end
44
+
45
+ def assets
46
+ CopyAssetsGenerator.assets
47
+ end
48
+
49
+ def asset_pipeline_enabled?
50
+ self.class.asset_pipeline_enabled?
51
+ end
52
52
  end
53
53
  end
54
54
  end
@@ -8,8 +8,6 @@ module ClientSideValidations
8
8
  copy_file 'initializer.rb', 'config/initializers/client_side_validations.rb'
9
9
  end
10
10
 
11
- private
12
-
13
11
  def self.installation_message
14
12
  "Copies initializer into config/initializers and #{super.downcase}"
15
13
  end
@@ -1,3 +1,10 @@
1
+
2
+ /*!
3
+ * Client Side Validations - v4.2.1 (https://github.com/DavyJonesLocker/client_side_validations)
4
+ * Copyright (c) 2016 Brian Cardarella
5
+ * Licensed under MIT (http://opensource.org/licenses/mit-license.php)
6
+ */
7
+
1
8
  (function() {
2
9
  var $, validateElement, validateForm, validatorsFor,
3
10
  indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: client_side_validations
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.2.0
4
+ version: 4.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Cardarella
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-07 00:00:00.000000000 Z
11
+ date: 2016-01-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -152,14 +152,14 @@ dependencies:
152
152
  requirements:
153
153
  - - "~>"
154
154
  - !ruby/object:Gem::Version
155
- version: '0.35'
155
+ version: 0.36.0
156
156
  type: :development
157
157
  prerelease: false
158
158
  version_requirements: !ruby/object:Gem::Requirement
159
159
  requirements:
160
160
  - - "~>"
161
161
  - !ruby/object:Gem::Version
162
- version: '0.35'
162
+ version: 0.36.0
163
163
  - !ruby/object:Gem::Dependency
164
164
  name: simplecov
165
165
  requirement: !ruby/object:Gem::Requirement