detox 1.1.0 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/detox.rb +3 -1
- data/lib/detox/array_validity.rb +11 -0
- data/lib/detox/validations/ordering.rb +15 -7
- data/lib/detox/validations/possession.rb +6 -6
- data/lib/detox/validations/values_uniqueness.rb +6 -6
- data/lib/detox/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: 365d9d489a7c82f900f04d1652bd38b45bdb5b53
|
4
|
+
data.tar.gz: b6cf2d7bb865be5bdf573ecc757b4656fdab517c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d5f8e3f9cdd9a36c99c7b1007b11848373954b54c30f28c5a59d401b4aedb164619139b78a33cc5b37c1a5824b81cd69a98a5c628e190e9cd83918c93657a0a8
|
7
|
+
data.tar.gz: 0e49ea7065b4bb3aaacb0649954dc935c554eaf7fa53193f2f0ef001958a9b865e1ebf46bed3ced2555f89485f1f56e42b5b1b45afee99ff24a7a240d6eaacb3
|
data/lib/detox.rb
CHANGED
@@ -8,5 +8,7 @@ require "detox/validations/all"
|
|
8
8
|
require "detox/validations/any"
|
9
9
|
|
10
10
|
ActiveModel::Validations.__send__(:include, Detox::Validations)
|
11
|
-
|
11
|
+
Dir[Pathname.new(File.dirname(__FILE__)).join("detox", "locales", "*.yml")].each do |f|
|
12
|
+
I18n.load_path << f
|
13
|
+
end
|
12
14
|
|
data/lib/detox/array_validity.rb
CHANGED
@@ -19,5 +19,16 @@ module Detox
|
|
19
19
|
values = values.reject(&:blank?) if options[:ignore_blank_value]
|
20
20
|
values
|
21
21
|
end
|
22
|
+
|
23
|
+
def validate_values(args)
|
24
|
+
record, attribute, value, message, opts = *args.values
|
25
|
+
|
26
|
+
values = convert_to_validatee(value, opts.slice(*Detox::ArrayValidity::RESERVED_OPTIONS))
|
27
|
+
return if values.blank?
|
28
|
+
|
29
|
+
unless values_valid?(values)
|
30
|
+
record.errors.add(attribute, message, opts)
|
31
|
+
end
|
32
|
+
end
|
22
33
|
end
|
23
34
|
end
|
@@ -7,18 +7,22 @@ module Detox::Validations
|
|
7
7
|
include Detox::ArrayValidity
|
8
8
|
|
9
9
|
def validate_each(record, attribute, value)
|
10
|
-
|
11
|
-
|
10
|
+
args = { :record => record,
|
11
|
+
:attribute => attribute,
|
12
|
+
:value => value,
|
13
|
+
:message => options[:message] || :invalid_as_order,
|
14
|
+
:options => options }
|
12
15
|
|
13
|
-
|
14
|
-
message = options[:message] || :invalid_as_order
|
15
|
-
record.errors.add(attribute, message)
|
16
|
-
end
|
16
|
+
validate_values(args)
|
17
17
|
end
|
18
18
|
|
19
19
|
private
|
20
20
|
def values_valid?(values)
|
21
|
-
valid_numbers(values.length)
|
21
|
+
same_values?(valid_numbers(values.length), values)
|
22
|
+
end
|
23
|
+
|
24
|
+
def same_values?(values, another)
|
25
|
+
normalize_values_for_compare(values) == normalize_values_for_compare(another)
|
22
26
|
end
|
23
27
|
|
24
28
|
def valid_numbers(length)
|
@@ -30,5 +34,9 @@ module Detox::Validations
|
|
30
34
|
num = options[:start_with].to_i
|
31
35
|
num.zero? ? 1 : num
|
32
36
|
end
|
37
|
+
|
38
|
+
def normalize_values_for_compare(values)
|
39
|
+
values.map(&:to_s).sort
|
40
|
+
end
|
33
41
|
end
|
34
42
|
end
|
@@ -8,13 +8,13 @@ module Detox::Validations
|
|
8
8
|
ERROR_MESSAGE = ":target must be supplied".freeze
|
9
9
|
|
10
10
|
def validate_each(record, attribute, value)
|
11
|
-
|
12
|
-
|
11
|
+
args = { :record => record,
|
12
|
+
:attribute => attribute,
|
13
|
+
:value => value,
|
14
|
+
:message => options[:message] || :possession,
|
15
|
+
:options => options.merge(:target => [options[:target]].flatten.join(", ")) }
|
13
16
|
|
14
|
-
|
15
|
-
message = options[:message] || :possession
|
16
|
-
record.errors.add(attribute, message, options.merge(:target => [options[:target]].flatten.join(", ")))
|
17
|
-
end
|
17
|
+
validate_values(args)
|
18
18
|
end
|
19
19
|
|
20
20
|
def check_validity!
|
@@ -7,13 +7,13 @@ module Detox::Validations
|
|
7
7
|
include Detox::ArrayValidity
|
8
8
|
|
9
9
|
def validate_each(record, attribute, value)
|
10
|
-
|
11
|
-
|
10
|
+
args = { :record => record,
|
11
|
+
:attribute => attribute,
|
12
|
+
:value => value,
|
13
|
+
:message => options[:message] || :values_not_unique,
|
14
|
+
:options => options }
|
12
15
|
|
13
|
-
|
14
|
-
message = options[:message] || :values_not_unique
|
15
|
-
record.errors.add(attribute, message)
|
16
|
-
end
|
16
|
+
validate_values(args)
|
17
17
|
end
|
18
18
|
|
19
19
|
private
|
data/lib/detox/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: detox
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- pinzolo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-11-
|
11
|
+
date: 2013-11-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|