activemodel 3.2.6 → 3.2.7.rc1
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.
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
## Rails 3.2.7 (unreleased)
|
2
|
+
|
3
|
+
* `validates_inclusion_of` and `validates_exclusion_of` now accept `:within` option as alias of `:in` as documented.
|
4
|
+
|
5
|
+
* Fix the the backport of the object dup with the ruby 1.9.3p194.
|
6
|
+
|
1
7
|
## Rails 3.2.6 (Jun 12, 2012)
|
2
8
|
|
3
9
|
* No changes.
|
@@ -168,8 +168,9 @@ module ActiveModel
|
|
168
168
|
# Clean the +Errors+ object if instance is duped
|
169
169
|
def initialize_dup(other) # :nodoc:
|
170
170
|
@errors = nil
|
171
|
+
super if defined?(super)
|
171
172
|
end
|
172
|
-
|
173
|
+
|
173
174
|
# Backport dup from 1.9 so that #initialize_dup gets called
|
174
175
|
unless Object.respond_to?(:initialize_dup)
|
175
176
|
def dup # :nodoc:
|
@@ -5,24 +5,27 @@ module ActiveModel
|
|
5
5
|
module Validations
|
6
6
|
class ExclusionValidator < EachValidator
|
7
7
|
ERROR_MESSAGE = "An object with the method #include? or a proc or lambda is required, " <<
|
8
|
-
"and must be supplied as the :in option of the configuration hash"
|
8
|
+
"and must be supplied as the :in (or :within) option of the configuration hash"
|
9
9
|
|
10
10
|
def check_validity!
|
11
|
-
unless [:include?, :call].any? { |method|
|
11
|
+
unless [:include?, :call].any? { |method| delimiter.respond_to?(method) }
|
12
12
|
raise ArgumentError, ERROR_MESSAGE
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
16
|
def validate_each(record, attribute, value)
|
17
|
-
delimiter = options[:in]
|
18
17
|
exclusions = delimiter.respond_to?(:call) ? delimiter.call(record) : delimiter
|
19
18
|
if exclusions.send(inclusion_method(exclusions), value)
|
20
|
-
record.errors.add(attribute, :exclusion, options.except(:in).merge!(:value => value))
|
19
|
+
record.errors.add(attribute, :exclusion, options.except(:in, :within).merge!(:value => value))
|
21
20
|
end
|
22
21
|
end
|
23
22
|
|
24
23
|
private
|
25
24
|
|
25
|
+
def delimiter
|
26
|
+
@delimiter ||= options[:in] || options[:within]
|
27
|
+
end
|
28
|
+
|
26
29
|
# In Ruby 1.9 <tt>Range#include?</tt> on non-numeric ranges checks all possible
|
27
30
|
# values in the range for equality, so it may be slow for large ranges. The new
|
28
31
|
# <tt>Range#cover?</tt> uses the previous logic of comparing a value with the
|
@@ -49,6 +52,7 @@ module ActiveModel
|
|
49
52
|
# part of. This can be supplied as a proc or lambda which returns an enumerable.
|
50
53
|
# If the enumerable is a range the test is performed with <tt>Range#cover?</tt>
|
51
54
|
# (backported in Active Support for 1.8), otherwise with <tt>include?</tt>.
|
55
|
+
# * <tt>:within</tt> - A synonym(or alias) for <tt>:in</tt>
|
52
56
|
# * <tt>:message</tt> - Specifies a custom error message (default is: "is reserved").
|
53
57
|
# * <tt>:allow_nil</tt> - If set to true, skips this validation if the attribute
|
54
58
|
# is +nil+ (default is +false+).
|
@@ -65,7 +69,7 @@ module ActiveModel
|
|
65
69
|
# the validation should not occur (e.g. <tt>:unless => :skip_validation</tt>,
|
66
70
|
# or <tt>:unless => Proc.new { |user| user.signup_step <= 2 }</tt>). The method,
|
67
71
|
# proc or string should return or evaluate to a true or false value.
|
68
|
-
# * <tt>:strict</tt> - Specifies whether validation should be strict.
|
72
|
+
# * <tt>:strict</tt> - Specifies whether validation should be strict.
|
69
73
|
# See <tt>ActiveModel::Validation#validates!</tt> for more information.
|
70
74
|
def validates_exclusion_of(*attr_names)
|
71
75
|
validates_with ExclusionValidator, _merge_attributes(attr_names)
|
@@ -5,24 +5,27 @@ module ActiveModel
|
|
5
5
|
module Validations
|
6
6
|
class InclusionValidator < EachValidator
|
7
7
|
ERROR_MESSAGE = "An object with the method #include? or a proc or lambda is required, " <<
|
8
|
-
"and must be supplied as the :in option of the configuration hash"
|
8
|
+
"and must be supplied as the :in (or :within) option of the configuration hash"
|
9
9
|
|
10
10
|
def check_validity!
|
11
|
-
unless [:include?, :call].any?{ |method|
|
11
|
+
unless [:include?, :call].any?{ |method| delimiter.respond_to?(method) }
|
12
12
|
raise ArgumentError, ERROR_MESSAGE
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
16
|
def validate_each(record, attribute, value)
|
17
|
-
delimiter = options[:in]
|
18
17
|
exclusions = delimiter.respond_to?(:call) ? delimiter.call(record) : delimiter
|
19
18
|
unless exclusions.send(inclusion_method(exclusions), value)
|
20
|
-
record.errors.add(attribute, :inclusion, options.except(:in).merge!(:value => value))
|
19
|
+
record.errors.add(attribute, :inclusion, options.except(:in, :within).merge!(:value => value))
|
21
20
|
end
|
22
21
|
end
|
23
22
|
|
24
23
|
private
|
25
24
|
|
25
|
+
def delimiter
|
26
|
+
@delimiter ||= options[:in] || options[:within]
|
27
|
+
end
|
28
|
+
|
26
29
|
# In Ruby 1.9 <tt>Range#include?</tt> on non-numeric ranges checks all possible
|
27
30
|
# values in the range for equality, so it may be slow for large ranges. The new
|
28
31
|
# <tt>Range#cover?</tt> uses the previous logic of comparing a value with the
|
@@ -48,6 +51,7 @@ module ActiveModel
|
|
48
51
|
# supplied as a proc or lambda which returns an enumerable. If the enumerable
|
49
52
|
# is a range the test is performed with <tt>Range#cover?</tt>
|
50
53
|
# (backported in Active Support for 1.8), otherwise with <tt>include?</tt>.
|
54
|
+
# * <tt>:within</tt> - A synonym(or alias) for <tt>:in</tt>
|
51
55
|
# * <tt>:message</tt> - Specifies a custom error message (default is: "is not
|
52
56
|
# included in the list").
|
53
57
|
# * <tt>:allow_nil</tt> - If set to true, skips this validation if the attribute
|
@@ -65,7 +69,7 @@ module ActiveModel
|
|
65
69
|
# if the validation should not occur (e.g. <tt>:unless => :skip_validation</tt>,
|
66
70
|
# or <tt>:unless => Proc.new { |user| user.signup_step <= 2 }</tt>). The method,
|
67
71
|
# proc or string should return or evaluate to a true or false value.
|
68
|
-
# * <tt>:strict</tt> - Specifies whether validation should be strict.
|
72
|
+
# * <tt>:strict</tt> - Specifies whether validation should be strict.
|
69
73
|
# See <tt>ActiveModel::Validation#validates!</tt> for more information.
|
70
74
|
def validates_inclusion_of(*attr_names)
|
71
75
|
validates_with InclusionValidator, _merge_attributes(attr_names)
|
data/lib/active_model/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activemodel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 475645881
|
5
|
+
prerelease: 6
|
6
6
|
segments:
|
7
7
|
- 3
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
|
9
|
+
- 7
|
10
|
+
- rc
|
11
|
+
- 1
|
12
|
+
version: 3.2.7.rc1
|
11
13
|
platform: ruby
|
12
14
|
authors:
|
13
15
|
- David Heinemeier Hansson
|
@@ -15,7 +17,7 @@ autorequire:
|
|
15
17
|
bindir: bin
|
16
18
|
cert_chain: []
|
17
19
|
|
18
|
-
date: 2012-
|
20
|
+
date: 2012-07-23 00:00:00 Z
|
19
21
|
dependencies:
|
20
22
|
- !ruby/object:Gem::Dependency
|
21
23
|
name: activesupport
|
@@ -25,12 +27,14 @@ dependencies:
|
|
25
27
|
requirements:
|
26
28
|
- - "="
|
27
29
|
- !ruby/object:Gem::Version
|
28
|
-
hash:
|
30
|
+
hash: 475645881
|
29
31
|
segments:
|
30
32
|
- 3
|
31
33
|
- 2
|
32
|
-
-
|
33
|
-
|
34
|
+
- 7
|
35
|
+
- rc
|
36
|
+
- 1
|
37
|
+
version: 3.2.7.rc1
|
34
38
|
type: :runtime
|
35
39
|
version_requirements: *id001
|
36
40
|
- !ruby/object:Gem::Dependency
|
@@ -118,12 +122,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
118
122
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
119
123
|
none: false
|
120
124
|
requirements:
|
121
|
-
- - "
|
125
|
+
- - ">"
|
122
126
|
- !ruby/object:Gem::Version
|
123
|
-
hash:
|
127
|
+
hash: 25
|
124
128
|
segments:
|
125
|
-
-
|
126
|
-
|
129
|
+
- 1
|
130
|
+
- 3
|
131
|
+
- 1
|
132
|
+
version: 1.3.1
|
127
133
|
requirements: []
|
128
134
|
|
129
135
|
rubyforge_project:
|