regressor 0.3.4 → 0.4.0
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/generators/regressor/model/validation/numericality.rb +53 -52
- data/lib/regressor/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: 8d64cf73d04c20acd51f9b2f556402f4db8bc5e7
|
4
|
+
data.tar.gz: a374e36cf41028092a97cdd2b80af909b4db39e2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4a468ed532fc84c26dcde872e0685b4ccfda97d2b95d3557a1889d27d67f302c10804d2da88f1714ef060c08c1f97f77e5df79f26ddeadcdc5b0a8f127c73f76
|
7
|
+
data.tar.gz: d7df289bfc83b549cdde66e98bab21c6a36c4bd26d410f4d556a0a9f4d53c8de3d4a3daf058fe74aeda25c440a09997d491fa112d0047511071eeaadfd9cfcc3
|
@@ -4,62 +4,63 @@ module Regressor
|
|
4
4
|
module Numericality
|
5
5
|
def numericality_validators
|
6
6
|
extract_validators(ActiveModel::Validations::NumericalityValidator).inject([]) do |result, validator|
|
7
|
-
validator.options.
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
result << "it { is_expected.to validate_numericality_of(:#{attribute}).even}"
|
12
|
-
end
|
13
|
-
when :only_integer
|
14
|
-
validator.attributes.each do |attribute|
|
15
|
-
result << "it { is_expected.to validate_numericality_of(:#{attribute}).only_integer}"
|
16
|
-
end
|
17
|
-
when :allow_nil
|
18
|
-
validator.attributes.each do |attribute|
|
19
|
-
result << "it { is_expected.to validate_numericality_of(:#{attribute}).allow_nil}"
|
20
|
-
end
|
21
|
-
end
|
7
|
+
if validator.options.blank?
|
8
|
+
result += validator_without_options(validator)
|
9
|
+
else
|
10
|
+
result += validator_with_options(validator)
|
22
11
|
end
|
23
12
|
result
|
24
13
|
end.uniq.join("\n\t")
|
25
14
|
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def validator_without_options(validator)
|
19
|
+
validator.attributes.map do |attribute|
|
20
|
+
"it { is_expected.to validate_numericality_of(:#{attribute})}"
|
21
|
+
end.flatten
|
22
|
+
end
|
23
|
+
|
24
|
+
def validator_with_options(validator)
|
25
|
+
validator.options.map do |k, v|
|
26
|
+
assertion = (v ? :to : :not_to)
|
27
|
+
case k
|
28
|
+
when :even
|
29
|
+
generate_spec_with_option(validator, :even, assertion)
|
30
|
+
when :only_integer
|
31
|
+
generate_spec_with_option(validator, :only_integer, assertion)
|
32
|
+
when :allow_nil
|
33
|
+
generate_spec_with_option(validator, :allow_nil, assertion)
|
34
|
+
when :less_than
|
35
|
+
generate_spec_with_option(validator, "is_less_than(#{v})") +
|
36
|
+
generate_spec_with_option(validator, "is_less_than(#{v + 1})", :not_to)
|
37
|
+
when :less_than_or_equal_to
|
38
|
+
generate_spec_with_option(validator, "is_less_than_or_equal_to(#{v})") +
|
39
|
+
generate_spec_with_option(validator, "is_less_than_or_equal_to(#{v + 1})", :not_to)
|
40
|
+
when :equal_to
|
41
|
+
generate_spec_with_option(validator, "is_equal_to(#{v})") +
|
42
|
+
generate_spec_with_option(validator, "is_equal_to(#{v + 1})", :not_to)
|
43
|
+
when :greater_than_or_equal_to
|
44
|
+
generate_spec_with_option(validator, "is_greater_than_or_equal_to(#{v})") +
|
45
|
+
generate_spec_with_option(validator, "is_greater_than_or_equal_to(#{v - 1})", :not_to)
|
46
|
+
when :greater_than
|
47
|
+
generate_spec_with_option(validator, "is_greater_than(#{v})") +
|
48
|
+
generate_spec_with_option(validator, "is_greater_than(#{v - 1})", :not_to)
|
49
|
+
when :odd
|
50
|
+
generate_spec_with_option(validator, :odd, assertion)
|
51
|
+
when :message
|
52
|
+
generate_spec_with_option(validator, "with_message('#{v}')")
|
53
|
+
end
|
54
|
+
end.flatten
|
55
|
+
end
|
56
|
+
|
57
|
+
def generate_spec_with_option(validator, matcher, assertion = :to)
|
58
|
+
validator.attributes.map do |attribute|
|
59
|
+
"it { is_expected.#{assertion} validate_numericality_of(:#{attribute}).#{matcher} }"
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
26
63
|
end
|
27
64
|
end
|
28
65
|
end
|
29
|
-
end
|
30
|
-
|
31
|
-
# * <tt>:message</tt> - A custom error message (default is: "is not a number").
|
32
|
-
# * <tt>:only_integer</tt> - Specifies whether the value has to be an
|
33
|
-
# integer, e.g. an integral value (default is +false+).
|
34
|
-
# * <tt>:allow_nil</tt> - Skip validation if attribute is +nil+ (default is
|
35
|
-
# +false+). Notice that for fixnum and float columns empty strings are
|
36
|
-
# converted to +nil+.
|
37
|
-
# * <tt>:greater_than</tt> - Specifies the value must be greater than the
|
38
|
-
# supplied value.
|
39
|
-
# * <tt>:greater_than_or_equal_to</tt> - Specifies the value must be
|
40
|
-
# greater than or equal the supplied value.
|
41
|
-
# * <tt>:equal_to</tt> - Specifies the value must be equal to the supplied
|
42
|
-
# value.
|
43
|
-
# * <tt>:less_than</tt> - Specifies the value must be less than the
|
44
|
-
# supplied value.
|
45
|
-
# * <tt>:less_than_or_equal_to</tt> - Specifies the value must be less
|
46
|
-
# than or equal the supplied value.
|
47
|
-
# * <tt>:other_than</tt> - Specifies the value must be other than the
|
48
|
-
# supplied value.
|
49
|
-
# * <tt>:odd</tt> - Specifies the value must be an odd number.
|
50
|
-
# * <tt>:even</tt> - Specifies the value must be an even number.
|
51
|
-
#
|
52
|
-
# There is also a list of default options supported by every validator:
|
53
|
-
# +:if+, +:unless+, +:on+, +:allow_nil+, +:allow_blank+, and +:strict+ .
|
54
|
-
# See <tt>ActiveModel::Validation#validates</tt> for more information
|
55
|
-
#
|
56
|
-
# The following checks can also be supplied with a proc or a symbol which
|
57
|
-
# corresponds to a method:
|
58
|
-
#
|
59
|
-
# * <tt>:greater_than</tt>
|
60
|
-
# * <tt>:greater_than_or_equal_to</tt>
|
61
|
-
# * <tt>:equal_to</tt>
|
62
|
-
# * <tt>:less_than</tt>
|
63
|
-
# * <tt>:less_than_or_equal_to</tt>
|
64
|
-
# * <tt>:only_integer</tt>
|
65
|
-
#
|
66
|
+
end
|
data/lib/regressor/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: regressor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Erwin Schens
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-03-
|
11
|
+
date: 2015-03-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: shoulda-matchers
|