9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/optional_validations.rb', line 9
def validates_with(*args, &block)
return __validates_with(*args, &block) unless args[1].present?
_if = Array(args[1][:if])
args[1][:attributes].each do |attr_name|
args[1][:attributes] = [attr_name]
args[1][:if] = _if.clone
args[1][:if].unshift -> do
if @__validate_only.present?
@__validate_only.include?(attr_name)
elsif @__validate_except.present?
! @__validate_except.include?(attr_name)
else
true
end
end
__validates_with(*args, &block)
end
end
|