client_side_validations 3.2.0.beta.5 → 3.2.0.beta.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -90,59 +90,66 @@ module ClientSideValidations::ActionView::Helpers
90
90
  def filter_validators(method, filters)
91
91
  if validators = @object.client_side_validation_hash[method]
92
92
  unfiltered_validators = validators.inject({}) do |unfiltered_validators, validator|
93
- unfiltered_validators[validator.first] = validator.last
94
- if has_filter_for_validator?(validator, filters)
95
- if filter_validator?(validator, filters)
96
- unfiltered_validators.delete(validator.first)
97
- elsif force_validator_despite_conditional?(validator, filters) && !can_run_validator?(validator, method)
98
- unfiltered_validators.delete(validator.first)
99
- end
100
- else
101
- if (conditional = (validator.last[:if] || validator.last[:unless]))
102
- result = case conditional
103
- when Symbol
104
- if @object.respond_to?(conditional)
105
- @object.send(conditional)
106
- else
107
- raise(ArgumentError, "unknown method called '#{conditional}'")
93
+ kind = validator.first
94
+ unfiltered_validators[kind] = validator.last.inject([]) do |validators_array, validator_hash|
95
+ if has_filter_for_validator?(kind, filters)
96
+ if filter_validator?(kind, filters)
97
+ next
98
+ elsif force_validator_despite_conditional?(kind, filters) && !can_run_validator?(validator_hash, method)
99
+ next
100
+ end
101
+ else
102
+ if (conditional = (validator_hash[:if] || validator_hash[:unless]))
103
+ result = case conditional
104
+ when Symbol
105
+ if @object.respond_to?(conditional)
106
+ @object.send(conditional)
107
+ else
108
+ raise(ArgumentError, "unknown method called '#{conditional}'")
109
+ end
110
+ when String
111
+ eval(conditional)
112
+ when Proc
113
+ conditional.call(@object)
108
114
  end
109
- when String
110
- eval(conditional)
111
- when Proc
112
- conditional.call(@object)
113
- end
114
115
 
115
- # :if was specified and result is false OR :unless was specified and result was true
116
- if (validator.last[:if] && !result) || (validator.last[:unless] && result)
117
- unfiltered_validators.delete(validator.first)
116
+ # :if was specified and result is false OR :unless was specified and result was true
117
+ if (validator_hash[:if] && !result) || (validator_hash[:unless] && result)
118
+ next
119
+ end
118
120
  end
121
+
119
122
  end
123
+
124
+ validators_array << validator_hash.clone
125
+ validators_array.last.delete_if { |key, value| key == :if || key == :unless }
126
+ validators_array
120
127
  end
121
- unfiltered_validators[validator.first].delete(:if) if unfiltered_validators[validator.first]
122
- unfiltered_validators[validator.first].delete(:unless) if unfiltered_validators[validator.first]
128
+
123
129
  unfiltered_validators
124
130
  end
125
131
 
132
+ unfiltered_validators.delete_if { |k, v| v.nil? }
126
133
  unfiltered_validators.empty? ? nil : unfiltered_validators
127
134
  end
128
135
  end
129
136
 
130
- def has_filter_for_validator?(validator, filters)
131
- filters && (filters == true || filters.key?(validator.first))
137
+ def has_filter_for_validator?(kind, filters)
138
+ filters && (filters == true || filters.key?(kind))
132
139
  end
133
140
 
134
- def filter_validator?(validator, filters)
135
- filters != true && filters[validator.first] == false
141
+ def filter_validator?(kind, filters)
142
+ filters != true && filters[kind] == false
136
143
  end
137
144
 
138
- def force_validator_despite_conditional?(validator, filters)
139
- filters == true || filters[validator.first] == true
145
+ def force_validator_despite_conditional?(kind, filters)
146
+ filters == true || filters[kind] == true
140
147
  end
141
148
 
142
- def can_run_validator?(validator, method)
149
+ def can_run_validator?(validator_hash, method)
143
150
  result = true
144
- if_result = run_if_validator(validator.last[:if], method)
145
- unless_result = run_unless_validator(validator.last[:unless], method)
151
+ if_result = run_if_validator(validator_hash[:if], method)
152
+ unless_result = run_unless_validator(validator_hash[:unless], method)
146
153
  result = result && if_result unless if_result.nil?
147
154
  result = result && unless_result unless unless_result.nil?
148
155
  result
@@ -173,4 +180,3 @@ module ClientSideValidations::ActionView::Helpers
173
180
  end
174
181
  end
175
182
  end
176
-
@@ -1,3 +1,3 @@
1
1
  module ClientSideValidations
2
- VERSION = '3.2.0.beta.5'
2
+ VERSION = '3.2.0.beta.6'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: client_side_validations
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.2.0.beta.5
4
+ version: 3.2.0.beta.6
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors:
@@ -206,7 +206,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
206
206
  version: '0'
207
207
  segments:
208
208
  - 0
209
- hash: 467030908926839385
209
+ hash: -2310212985539069704
210
210
  required_rubygems_version: !ruby/object:Gem::Requirement
211
211
  none: false
212
212
  requirements: