detox 1.1.0 → 1.1.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: 819d53441b8e4cbfe446f921fd1c350410c1efbd
4
- data.tar.gz: 486a61f7e2b0f2990473245b9bf4b0b030043116
3
+ metadata.gz: 365d9d489a7c82f900f04d1652bd38b45bdb5b53
4
+ data.tar.gz: b6cf2d7bb865be5bdf573ecc757b4656fdab517c
5
5
  SHA512:
6
- metadata.gz: 36d92e758704e0d1694c35577947bda5d6956f13b52a11b09403e0358038d49567e86a86d5a6021fc6aae477c1f05ebe71667f314addf50bd787154b79e70659
7
- data.tar.gz: 6ead87d992b548fc9964c432693ff5be0274f73d46f4768dfc3e6badbdae15e994585d938510fa1a4bbfce555cfe2d61ff91fa9c2461d82283ae139f48bd7a51
6
+ metadata.gz: d5f8e3f9cdd9a36c99c7b1007b11848373954b54c30f28c5a59d401b4aedb164619139b78a33cc5b37c1a5824b81cd69a98a5c628e190e9cd83918c93657a0a8
7
+ data.tar.gz: 0e49ea7065b4bb3aaacb0649954dc935c554eaf7fa53193f2f0ef001958a9b865e1ebf46bed3ced2555f89485f1f56e42b5b1b45afee99ff24a7a240d6eaacb3
@@ -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
- I18n.load_path << Dir[Pathname.new(File.dirname(__FILE__)).join("detox", "locales", "*.yml")]
11
+ Dir[Pathname.new(File.dirname(__FILE__)).join("detox", "locales", "*.yml")].each do |f|
12
+ I18n.load_path << f
13
+ end
12
14
 
@@ -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
- values = convert_to_validatee(value, options.slice(*Detox::ArrayValidity::RESERVED_OPTIONS))
11
- return if values.blank?
10
+ args = { :record => record,
11
+ :attribute => attribute,
12
+ :value => value,
13
+ :message => options[:message] || :invalid_as_order,
14
+ :options => options }
12
15
 
13
- unless values_valid?(values)
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).map(&:to_s).sort == values.map(&:to_s).sort
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
- values = convert_to_validatee(value, options.slice(*Detox::ArrayValidity::RESERVED_OPTIONS))
12
- return if values.blank?
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
- unless values_valid?(values)
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
- values = convert_to_validatee(value, options.slice(*Detox::ArrayValidity::RESERVED_OPTIONS))
11
- return if values.blank?
10
+ args = { :record => record,
11
+ :attribute => attribute,
12
+ :value => value,
13
+ :message => options[:message] || :values_not_unique,
14
+ :options => options }
12
15
 
13
- unless values_valid?(values)
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
@@ -1,4 +1,4 @@
1
1
  # coding: utf-8
2
2
  module Detox
3
- VERSION = "1.1.0"
3
+ VERSION = "1.1.1"
4
4
  end
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.0
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-14 00:00:00.000000000 Z
11
+ date: 2013-11-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel