run_cl 1.6.1 → 1.6.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/run_cl/run_validator.rb +4 -7
- data/lib/run_cl/uniq_run_validator.rb +13 -18
- data/lib/run_cl/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6a17e5a29daeca5dfdc021df36397c9999a472d8
|
4
|
+
data.tar.gz: 4e71f0fc8392d0e8d9ba3a274d0bed4947533756
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 91a7f3ac29364d5259cd66d8abfd81f1ecf8fdb29de0f748365fd536073a55f58e6d12b9f18d40477d682c6f7c8bf95980abcdc4e2a1e1398e7a2802af9359e0
|
7
|
+
data.tar.gz: 819802be60bf82ccdb50325b2cc120e3b72e16a87f5a0a8d455fb3a09689f3174ecb3670ad3f82798098474f2f75969f277fa51f4679f19c97d345667d97fcb7
|
data/lib/run_cl/run_validator.rb
CHANGED
@@ -1,13 +1,10 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
class RunValidator < ActiveModel::
|
4
|
-
def
|
5
|
-
options[:
|
6
|
-
record.errors[attribute.to_sym] << 'no es válido' unless Run.valid?(record.send(attribute))
|
7
|
-
end
|
3
|
+
class RunValidator < ActiveModel::EachValidator
|
4
|
+
def validate_each(record, attribute, value)
|
5
|
+
record.errors[attribute] << (options[:message] || 'no es válido') unless Run.valid?(value)
|
8
6
|
end
|
9
7
|
|
10
|
-
private
|
11
8
|
# TODO - locales
|
12
9
|
# record.errors[attribute.to_sym] << I18n.t('run.invalid') unless Run.valid? record.send(attribute)
|
13
|
-
end
|
10
|
+
end
|
@@ -1,28 +1,23 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
class UniqRunValidator < ActiveModel::
|
4
|
-
def
|
5
|
-
|
6
|
-
run = Run.remove_format record.send(attribute)
|
3
|
+
class UniqRunValidator < ActiveModel::EachValidator
|
4
|
+
def validate_each(record, attribute, value)
|
5
|
+
run = Run.remove_format value
|
7
6
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
if options[:scope]
|
16
|
-
matchers = matchers.where(options[:scope] => record.send(options[:scope]))
|
17
|
-
end
|
18
|
-
|
19
|
-
matchers.any?
|
7
|
+
matchers = []
|
8
|
+
if record.new_record?
|
9
|
+
matchers = record.class.where(attribute => run)
|
10
|
+
else
|
11
|
+
matchers = record.class.where('? = ? AND id != ?', attribute, run, record.id)
|
12
|
+
end
|
20
13
|
|
21
|
-
|
14
|
+
if options[:scope]
|
15
|
+
matchers = matchers.where(options[:scope] => record.send(options[:scope]))
|
22
16
|
end
|
17
|
+
|
18
|
+
record.errors[attribute.to_sym] << (options[:message] || 'ya está en uso') if matchers.any?
|
23
19
|
end
|
24
20
|
|
25
|
-
private
|
26
21
|
# TODO - locales
|
27
22
|
# record.errors[attribute.to_sym] << I18n.t('run.in_use') unless Run.valid? record.send(attribute)
|
28
23
|
end
|
data/lib/run_cl/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: run_cl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.6.
|
4
|
+
version: 1.6.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- mespina
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-07-01 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Formateador/Desformateador, Generador, Validador de Rut Chilenos
|
14
14
|
email:
|