dm-validations 0.10.2 → 1.0.0.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/.gitignore +36 -0
- data/Gemfile +143 -0
- data/README.rdoc +52 -102
- data/Rakefile +3 -3
- data/VERSION +1 -1
- data/dm-validations.gemspec +126 -14
- data/lib/dm-validations.rb +78 -18
- data/lib/dm-validations/auto_validate.rb +27 -23
- data/lib/dm-validations/contextual_validators.rb +3 -3
- data/lib/dm-validations/formats/email.rb +3 -3
- data/lib/dm-validations/formats/url.rb +3 -3
- data/lib/dm-validations/support/context.rb +1 -1
- data/lib/dm-validations/validation_errors.rb +5 -7
- data/lib/dm-validations/validators/absent_field_validator.rb +13 -9
- data/lib/dm-validations/validators/acceptance_validator.rb +10 -7
- data/lib/dm-validations/validators/block_validator.rb +3 -3
- data/lib/dm-validations/validators/confirmation_validator.rb +10 -7
- data/lib/dm-validations/validators/format_validator.rb +14 -10
- data/lib/dm-validations/validators/generic_validator.rb +3 -3
- data/lib/dm-validations/validators/length_validator.rb +10 -7
- data/lib/dm-validations/validators/method_validator.rb +3 -3
- data/lib/dm-validations/validators/numeric_validator.rb +25 -14
- data/lib/dm-validations/validators/primitive_validator.rb +12 -8
- data/lib/dm-validations/validators/required_field_validator.rb +12 -9
- data/lib/dm-validations/validators/uniqueness_validator.rb +9 -6
- data/lib/dm-validations/validators/within_validator.rb +3 -3
- data/spec/fixtures/barcode.rb +10 -2
- data/spec/fixtures/basketball_court.rb +7 -7
- data/spec/fixtures/basketball_player.rb +3 -3
- data/spec/fixtures/beta_tester_account.rb +4 -4
- data/spec/fixtures/bill_of_landing.rb +7 -7
- data/spec/fixtures/boat_dock.rb +2 -2
- data/spec/fixtures/city.rb +1 -1
- data/spec/fixtures/company.rb +7 -7
- data/spec/fixtures/corporate_world.rb +24 -26
- data/spec/fixtures/country.rb +1 -1
- data/spec/fixtures/currency.rb +4 -4
- data/spec/fixtures/ethernet_frame.rb +5 -5
- data/spec/fixtures/event.rb +2 -2
- data/spec/fixtures/g3_concert.rb +3 -3
- data/spec/fixtures/jabberwock.rb +2 -2
- data/spec/fixtures/kayak.rb +2 -2
- data/spec/fixtures/lernean_hydra.rb +3 -3
- data/spec/fixtures/mathematical_function.rb +2 -2
- data/spec/fixtures/memory_object.rb +3 -3
- data/spec/fixtures/mittelschnauzer.rb +3 -3
- data/spec/fixtures/motor_launch.rb +1 -1
- data/spec/fixtures/page.rb +3 -3
- data/spec/fixtures/phone_number.rb +2 -2
- data/spec/fixtures/pirogue.rb +2 -2
- data/spec/fixtures/programming_language.rb +3 -3
- data/spec/fixtures/reservation.rb +5 -5
- data/spec/fixtures/scm_operation.rb +42 -45
- data/spec/fixtures/sms_message.rb +1 -1
- data/spec/fixtures/udp_packet.rb +3 -3
- data/spec/integration/absent_field_validator/absent_field_validator_spec.rb +6 -6
- data/spec/integration/acceptance_validator/acceptance_validator_spec.rb +3 -3
- data/spec/integration/automatic_validation/inferred_length_validation_spec.rb +5 -5
- data/spec/integration/automatic_validation/spec_helper.rb +1 -1
- data/spec/integration/block_validator/block_validator_spec.rb +2 -2
- data/spec/integration/conditional_validation/if_condition_spec.rb +3 -3
- data/spec/integration/confirmation_validator/confirmation_validator_spec.rb +3 -3
- data/spec/integration/datamapper_models/association_validation_spec.rb +5 -5
- data/spec/integration/datamapper_models/inheritance_spec.rb +6 -6
- data/spec/integration/duplicated_validations/duplicated_validations_spec.rb +3 -3
- data/spec/integration/format_validator/email_format_validator_spec.rb +6 -6
- data/spec/integration/format_validator/format_validator_spec.rb +8 -8
- data/spec/integration/format_validator/regexp_validator_spec.rb +4 -4
- data/spec/integration/format_validator/url_format_validator_spec.rb +4 -4
- data/spec/integration/length_validator/default_value_spec.rb +3 -3
- data/spec/integration/length_validator/equality_spec.rb +4 -4
- data/spec/integration/length_validator/error_message_spec.rb +3 -3
- data/spec/integration/length_validator/maximum_spec.rb +3 -3
- data/spec/integration/length_validator/minimum_spec.rb +3 -3
- data/spec/integration/length_validator/range_spec.rb +3 -3
- data/spec/integration/method_validator/method_validator_spec.rb +8 -8
- data/spec/integration/numeric_validator/equality_with_float_type_spec.rb +7 -7
- data/spec/integration/numeric_validator/equality_with_integer_type_spec.rb +5 -5
- data/spec/integration/numeric_validator/float_type_spec.rb +3 -3
- data/spec/integration/numeric_validator/gt_with_float_type_spec.rb +3 -3
- data/spec/integration/numeric_validator/gte_with_float_type_spec.rb +3 -3
- data/spec/integration/numeric_validator/lt_with_float_type_spec.rb +3 -3
- data/spec/integration/numeric_validator/lte_with_float_type_spec.rb +3 -3
- data/spec/integration/primitive_validator/primitive_validator_spec.rb +4 -4
- data/spec/integration/pure_ruby_objects/plain_old_ruby_object_validation_spec.rb +4 -4
- data/spec/integration/required_field_validator/association_spec.rb +19 -51
- data/spec/integration/required_field_validator/boolean_type_value_spec.rb +4 -1
- data/spec/integration/required_field_validator/date_type_value_spec.rb +4 -2
- data/spec/integration/required_field_validator/datetime_type_value_spec.rb +4 -2
- data/spec/integration/required_field_validator/float_type_value_spec.rb +4 -2
- data/spec/integration/required_field_validator/integer_type_value_spec.rb +4 -2
- data/spec/integration/required_field_validator/plain_old_ruby_object_spec.rb +6 -4
- data/spec/integration/required_field_validator/string_type_value_spec.rb +3 -1
- data/spec/integration/required_field_validator/text_type_value_spec.rb +3 -1
- data/spec/integration/shared/valid_and_invalid_model.rb +8 -0
- data/spec/integration/uniqueness_validator/uniqueness_validator_spec.rb +29 -25
- data/spec/integration/within_validator/within_validator_spec.rb +6 -6
- data/spec/public/resource_spec.rb +47 -9
- data/spec/spec_helper.rb +13 -27
- data/spec/unit/contextual_validators/emptiness_spec.rb +4 -4
- data/spec/unit/contextual_validators/execution_spec.rb +6 -6
- data/spec/unit/contextual_validators/spec_helper.rb +3 -3
- data/spec/unit/generic_validator/equality_operator_spec.rb +7 -7
- data/spec/unit/validation_errors/adding_spec.rb +2 -2
- data/spec/unit/validation_errors/emptiness_spec.rb +2 -2
- data/spec/unit/validation_errors/enumerable_spec.rb +2 -2
- data/tasks/local_gemfile.rake +18 -0
- data/tasks/spec.rake +0 -3
- metadata +157 -25
data/lib/dm-validations.rb
CHANGED
@@ -1,3 +1,50 @@
|
|
1
|
+
require 'dm-core'
|
2
|
+
|
3
|
+
begin
|
4
|
+
|
5
|
+
require 'active_support/core_ext/class/attribute_accessors'
|
6
|
+
require 'active_support/core_ext/object/blank'
|
7
|
+
require 'active_support/ordered_hash'
|
8
|
+
|
9
|
+
class Object
|
10
|
+
# If receiver is callable, calls it and
|
11
|
+
# returns result. If not, just returns receiver
|
12
|
+
# itself
|
13
|
+
#
|
14
|
+
# @return [Object]
|
15
|
+
def try_call(*args)
|
16
|
+
if self.respond_to?(:call)
|
17
|
+
self.call(*args)
|
18
|
+
else
|
19
|
+
self
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
rescue LoadError
|
25
|
+
|
26
|
+
require 'extlib/class'
|
27
|
+
require 'extlib/dictionary'
|
28
|
+
require 'extlib/blank'
|
29
|
+
require 'extlib/try_dup'
|
30
|
+
require 'extlib/object'
|
31
|
+
|
32
|
+
module ActiveSupport
|
33
|
+
OrderedHash = Dictionary
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
module DataMapper
|
39
|
+
class Property
|
40
|
+
def self.new(model, name, options = {}, type = nil)
|
41
|
+
property = super
|
42
|
+
property.model.auto_generate_validations(property)
|
43
|
+
property
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
1
48
|
require 'dm-validations/exceptions'
|
2
49
|
require 'dm-validations/validation_errors'
|
3
50
|
require 'dm-validations/contextual_validators'
|
@@ -21,7 +68,8 @@ require 'dm-validations/support/context'
|
|
21
68
|
require 'dm-validations/support/object'
|
22
69
|
|
23
70
|
module DataMapper
|
24
|
-
module
|
71
|
+
module Validations
|
72
|
+
|
25
73
|
Model.append_inclusions self
|
26
74
|
|
27
75
|
extend Chainable
|
@@ -57,7 +105,7 @@ module DataMapper
|
|
57
105
|
|
58
106
|
chainable do
|
59
107
|
def save_self(*)
|
60
|
-
return false unless validation_context_stack.empty? || valid?(current_validation_context)
|
108
|
+
return false unless !dirty_self? || validation_context_stack.empty? || valid?(current_validation_context)
|
61
109
|
super
|
62
110
|
end
|
63
111
|
end
|
@@ -104,19 +152,19 @@ module DataMapper
|
|
104
152
|
end
|
105
153
|
|
106
154
|
module ClassMethods
|
107
|
-
include DataMapper::
|
108
|
-
include DataMapper::
|
109
|
-
include DataMapper::
|
110
|
-
include DataMapper::
|
111
|
-
include DataMapper::
|
112
|
-
include DataMapper::
|
113
|
-
include DataMapper::
|
114
|
-
include DataMapper::
|
115
|
-
include DataMapper::
|
116
|
-
include DataMapper::
|
117
|
-
include DataMapper::
|
118
|
-
include DataMapper::
|
119
|
-
include DataMapper::
|
155
|
+
include DataMapper::Validations::ValidatesPresence
|
156
|
+
include DataMapper::Validations::ValidatesAbsence
|
157
|
+
include DataMapper::Validations::ValidatesConfirmation
|
158
|
+
include DataMapper::Validations::ValidatesPrimitiveType
|
159
|
+
include DataMapper::Validations::ValidatesAcceptance
|
160
|
+
include DataMapper::Validations::ValidatesFormat
|
161
|
+
include DataMapper::Validations::ValidatesLength
|
162
|
+
include DataMapper::Validations::ValidatesWithin
|
163
|
+
include DataMapper::Validations::ValidatesNumericality
|
164
|
+
include DataMapper::Validations::ValidatesWithMethod
|
165
|
+
include DataMapper::Validations::ValidatesWithBlock
|
166
|
+
include DataMapper::Validations::ValidatesUniqueness
|
167
|
+
include DataMapper::Validations::AutoValidations
|
120
168
|
|
121
169
|
# Return the set of contextual validators or create a new one
|
122
170
|
#
|
@@ -124,6 +172,13 @@ module DataMapper
|
|
124
172
|
@validators ||= ContextualValidators.new
|
125
173
|
end
|
126
174
|
|
175
|
+
def inherited(base)
|
176
|
+
super
|
177
|
+
validators.contexts.each do |context, validators|
|
178
|
+
base.validators.context(context).concat(validators)
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
127
182
|
private
|
128
183
|
|
129
184
|
# Clean up the argument list and return a opts hash, including the
|
@@ -161,10 +216,10 @@ module DataMapper
|
|
161
216
|
#
|
162
217
|
# @param [Array<Symbol>] fields
|
163
218
|
# Fields given to validation macro, example:
|
164
|
-
# [:first_name, :last_name] in
|
219
|
+
# [:first_name, :last_name] in validates_presence_of :first_name, :last_name
|
165
220
|
#
|
166
221
|
# @param [Class] klazz
|
167
|
-
# Validator class, example: DataMapper::
|
222
|
+
# Validator class, example: DataMapper::Validations::LengthValidator
|
168
223
|
def add_validator_to_context(opts, fields, validator_class)
|
169
224
|
fields.each do |field|
|
170
225
|
validator = validator_class.new(field, opts.dup)
|
@@ -178,5 +233,10 @@ module DataMapper
|
|
178
233
|
end
|
179
234
|
end
|
180
235
|
end # module ClassMethods
|
181
|
-
end # module
|
236
|
+
end # module Validations
|
237
|
+
|
238
|
+
# Provide a const alias for backward compatibility with plugins
|
239
|
+
# This is scheduled to go away though, definitely before 1.0
|
240
|
+
Validate = Validations
|
241
|
+
|
182
242
|
end # module DataMapper
|
@@ -1,11 +1,11 @@
|
|
1
1
|
module DataMapper
|
2
2
|
class Property
|
3
3
|
# for options_with_message
|
4
|
-
|
4
|
+
accept_options :message, :messages, :set, :validates, :auto_validation, :format
|
5
5
|
end
|
6
6
|
|
7
|
-
module
|
8
|
-
module
|
7
|
+
module Validations
|
8
|
+
module AutoValidations
|
9
9
|
@disable_auto_validations = false
|
10
10
|
|
11
11
|
# adds message for validator
|
@@ -41,7 +41,7 @@ module DataMapper
|
|
41
41
|
#
|
42
42
|
# :required => true
|
43
43
|
# Setting the option :required to true causes a
|
44
|
-
#
|
44
|
+
# validates_presence_of validator to be automatically created on
|
45
45
|
# the property
|
46
46
|
#
|
47
47
|
# :length => 20
|
@@ -59,12 +59,12 @@ module DataMapper
|
|
59
59
|
# validator to be automatically created on the property
|
60
60
|
#
|
61
61
|
# Integer type
|
62
|
-
# Using a Integer type causes a
|
62
|
+
# Using a Integer type causes a validates_numericality_of
|
63
63
|
# validator to be created for the property. integer_only
|
64
64
|
# is set to true
|
65
65
|
#
|
66
66
|
# BigDecimal or Float type
|
67
|
-
# Using a Integer type causes a
|
67
|
+
# Using a Integer type causes a validates_numericality_of
|
68
68
|
# validator to be created for the property. integer_only
|
69
69
|
# is set to false, and precision/scale match the property
|
70
70
|
#
|
@@ -127,18 +127,18 @@ module DataMapper
|
|
127
127
|
def infer_presence_validation_for(property, options)
|
128
128
|
return if skip_presence_validation?(property)
|
129
129
|
|
130
|
-
|
130
|
+
validates_presence_of property.name, options_with_message(options, property, :presence)
|
131
131
|
end
|
132
132
|
|
133
133
|
def infer_length_validation_for(property, options)
|
134
|
-
return unless [ String, DataMapper::
|
134
|
+
return unless [ DataMapper::Property::String, DataMapper::Property::Text ].include?(property.class)
|
135
135
|
|
136
|
-
case length = property.options.fetch(:length, DataMapper::Property::DEFAULT_LENGTH)
|
136
|
+
case length = property.options.fetch(:length, DataMapper::Property::String::DEFAULT_LENGTH)
|
137
137
|
when Range then options[:within] = length
|
138
138
|
else options[:maximum] = length
|
139
139
|
end
|
140
140
|
|
141
|
-
|
141
|
+
validates_length_of property.name, options_with_message(options, property, :length)
|
142
142
|
end
|
143
143
|
|
144
144
|
def infer_format_validation_for(property, options)
|
@@ -146,7 +146,7 @@ module DataMapper
|
|
146
146
|
|
147
147
|
options[:with] = property.options[:format]
|
148
148
|
|
149
|
-
|
149
|
+
validates_format_of property.name, options_with_message(options, property, :format)
|
150
150
|
end
|
151
151
|
|
152
152
|
def infer_uniqueness_validation_for(property, options)
|
@@ -156,9 +156,9 @@ module DataMapper
|
|
156
156
|
when Array, Symbol
|
157
157
|
options[:scope] = Array(value)
|
158
158
|
|
159
|
-
|
159
|
+
validates_uniqueness_of property.name, options_with_message(options, property, :is_unique)
|
160
160
|
when TrueClass
|
161
|
-
|
161
|
+
validates_uniqueness_of property.name, options_with_message(options, property, :is_unique)
|
162
162
|
end
|
163
163
|
end
|
164
164
|
|
@@ -171,23 +171,27 @@ module DataMapper
|
|
171
171
|
end
|
172
172
|
|
173
173
|
def infer_type_validation_for(property, options)
|
174
|
-
|
175
|
-
options[:lte] = property.max if property.max
|
174
|
+
return if property.custom?
|
176
175
|
|
177
|
-
if
|
176
|
+
if property.kind_of?(Property::Numeric)
|
177
|
+
options[:gte] = property.min if property.min
|
178
|
+
options[:lte] = property.max if property.max
|
179
|
+
end
|
180
|
+
|
181
|
+
if Integer == property.primitive
|
178
182
|
options[:integer_only] = true
|
179
183
|
|
180
|
-
|
181
|
-
elsif BigDecimal == property.
|
184
|
+
validates_numericality_of property.name, options_with_message(options, property, :is_number)
|
185
|
+
elsif BigDecimal == property.primitive || Float == property.primitive
|
182
186
|
options[:precision] = property.precision
|
183
187
|
options[:scale] = property.scale
|
184
188
|
|
185
|
-
|
186
|
-
|
189
|
+
validates_numericality_of property.name, options_with_message(options, property, :is_number)
|
190
|
+
else
|
187
191
|
# We only need this in the case we don't already
|
188
192
|
# have a numeric validator, because otherwise
|
189
193
|
# it will cause duplicate validation errors
|
190
|
-
|
194
|
+
validates_primitive_type_of property.name, options_with_message(options, property, :is_primitive)
|
191
195
|
end
|
192
196
|
end
|
193
197
|
|
@@ -196,6 +200,6 @@ module DataMapper
|
|
196
200
|
def skip_presence_validation?(property)
|
197
201
|
property.allow_blank? || property.serial?
|
198
202
|
end
|
199
|
-
end # module
|
200
|
-
end # module
|
203
|
+
end # module AutoValidations
|
204
|
+
end # module Validations
|
201
205
|
end # module DataMapper
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'forwardable'
|
2
2
|
|
3
3
|
module DataMapper
|
4
|
-
module
|
4
|
+
module Validations
|
5
5
|
|
6
6
|
##
|
7
7
|
#
|
@@ -31,7 +31,7 @@ module DataMapper
|
|
31
31
|
#
|
32
32
|
# @param [String]
|
33
33
|
# Context name for which return validators
|
34
|
-
# @return [Array<DataMapper::
|
34
|
+
# @return [Array<DataMapper::Validations::GenericValidator>]
|
35
35
|
# An array of validators
|
36
36
|
def context(name)
|
37
37
|
contexts[name] ||= []
|
@@ -60,5 +60,5 @@ module DataMapper
|
|
60
60
|
end
|
61
61
|
|
62
62
|
end # module ContextualValidators
|
63
|
-
end # module
|
63
|
+
end # module Validations
|
64
64
|
end # module DataMapper
|
@@ -1,12 +1,12 @@
|
|
1
1
|
# encoding: binary
|
2
2
|
|
3
3
|
module DataMapper
|
4
|
-
module
|
4
|
+
module Validations
|
5
5
|
module Format
|
6
6
|
module Email
|
7
7
|
|
8
8
|
def self.included(base)
|
9
|
-
DataMapper::
|
9
|
+
DataMapper::Validations::FormatValidator::FORMATS.merge!(
|
10
10
|
:email_address => [ EmailAddress, lambda { |field, value| '%s is not a valid email address'.t(value) }]
|
11
11
|
)
|
12
12
|
end
|
@@ -39,5 +39,5 @@ module DataMapper
|
|
39
39
|
|
40
40
|
end # module Email
|
41
41
|
end # module Format
|
42
|
-
end # module
|
42
|
+
end # module Validations
|
43
43
|
end # module DataMapper
|
@@ -1,12 +1,12 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
module DataMapper
|
4
|
-
module
|
4
|
+
module Validations
|
5
5
|
module Format
|
6
6
|
module Url
|
7
7
|
|
8
8
|
def self.included(base)
|
9
|
-
DataMapper::
|
9
|
+
DataMapper::Validations::FormatValidator::FORMATS.merge!(
|
10
10
|
:url => [ Url, lambda { |field, value| '%s is not a valid URL'.t(value) }]
|
11
11
|
)
|
12
12
|
end
|
@@ -18,5 +18,5 @@ module DataMapper
|
|
18
18
|
|
19
19
|
end # module Url
|
20
20
|
end # module Format
|
21
|
-
end # module
|
21
|
+
end # module Validations
|
22
22
|
end # module DataMapper
|
@@ -1,7 +1,5 @@
|
|
1
|
-
require 'extlib/dictionary'
|
2
|
-
|
3
1
|
module DataMapper
|
4
|
-
module
|
2
|
+
module Validations
|
5
3
|
|
6
4
|
##
|
7
5
|
#
|
@@ -40,7 +38,7 @@ module DataMapper
|
|
40
38
|
cattr_writer :default_error_messages
|
41
39
|
|
42
40
|
def self.default_error_message(key, field, *values)
|
43
|
-
field =
|
41
|
+
field = ActiveSupport::Inflector.humanize(field)
|
44
42
|
@@default_error_messages[key] % [field, *values].flatten
|
45
43
|
end
|
46
44
|
|
@@ -48,7 +46,7 @@ module DataMapper
|
|
48
46
|
|
49
47
|
def initialize(resource)
|
50
48
|
@resource = resource
|
51
|
-
@errors =
|
49
|
+
@errors = ActiveSupport::OrderedHash.new { |h,k| h[k] = [] }
|
52
50
|
end
|
53
51
|
|
54
52
|
# Clear existing validation errors.
|
@@ -87,7 +85,7 @@ module DataMapper
|
|
87
85
|
# Return validation errors for a particular field_name.
|
88
86
|
#
|
89
87
|
# @param [Symbol] field_name the name of the field you want an error for
|
90
|
-
# @return [Array<DataMapper::
|
88
|
+
# @return [Array<DataMapper::Validations::Error>]
|
91
89
|
# array of validation errors or empty array, if there are no errors on given field
|
92
90
|
def on(field_name)
|
93
91
|
errors_for_field = errors[field_name]
|
@@ -115,5 +113,5 @@ module DataMapper
|
|
115
113
|
end
|
116
114
|
|
117
115
|
end # class ValidationErrors
|
118
|
-
end # module
|
116
|
+
end # module Validations
|
119
117
|
end # module DataMapper
|
@@ -1,11 +1,11 @@
|
|
1
1
|
module DataMapper
|
2
|
-
module
|
2
|
+
module Validations
|
3
3
|
|
4
4
|
##
|
5
5
|
#
|
6
6
|
# @author Guy van den Berg
|
7
7
|
# @since 0.9
|
8
|
-
class
|
8
|
+
class AbsenceValidator < GenericValidator
|
9
9
|
def call(target)
|
10
10
|
return true if target.validation_property_value(field_name).blank?
|
11
11
|
|
@@ -14,9 +14,11 @@ module DataMapper
|
|
14
14
|
|
15
15
|
false
|
16
16
|
end
|
17
|
-
end # class
|
17
|
+
end # class AbsenceValidator
|
18
18
|
|
19
|
-
module
|
19
|
+
module ValidatesAbsence
|
20
|
+
|
21
|
+
extend Deprecate
|
20
22
|
|
21
23
|
##
|
22
24
|
# Validates that the specified attribute is "blank" via the attribute's
|
@@ -36,18 +38,20 @@ module DataMapper
|
|
36
38
|
# property :another_unwanted, String
|
37
39
|
# property :yet_again, String
|
38
40
|
#
|
39
|
-
#
|
40
|
-
#
|
41
|
+
# validates_absence_of :unwanted_attribute
|
42
|
+
# validates_absence_of :another_unwanted, :yet_again
|
41
43
|
#
|
42
44
|
# # a call to valid? will return false unless
|
43
45
|
# # all three attributes are blank
|
44
46
|
# end
|
45
47
|
#
|
46
|
-
def
|
48
|
+
def validates_absence_of(*fields)
|
47
49
|
opts = opts_from_validator_args(fields)
|
48
|
-
add_validator_to_context(opts, fields, DataMapper::
|
50
|
+
add_validator_to_context(opts, fields, DataMapper::Validations::AbsenceValidator)
|
49
51
|
end
|
50
52
|
|
53
|
+
deprecate :validates_absent, :validates_absence_of
|
54
|
+
|
51
55
|
end # module ValidatesAbsent
|
52
|
-
end # module
|
56
|
+
end # module Validations
|
53
57
|
end # module DataMapper
|
@@ -1,5 +1,5 @@
|
|
1
1
|
module DataMapper
|
2
|
-
module
|
2
|
+
module Validations
|
3
3
|
|
4
4
|
##
|
5
5
|
#
|
@@ -34,7 +34,8 @@ module DataMapper
|
|
34
34
|
end
|
35
35
|
end # class AcceptanceValidator
|
36
36
|
|
37
|
-
module
|
37
|
+
module ValidatesAcceptance
|
38
|
+
extend Deprecate
|
38
39
|
|
39
40
|
##
|
40
41
|
# Validates that the attributes's value is in the set of accepted values.
|
@@ -52,19 +53,21 @@ module DataMapper
|
|
52
53
|
#
|
53
54
|
# property :license_agreement_accepted, String
|
54
55
|
# property :terms_accepted, String
|
55
|
-
#
|
56
|
-
#
|
56
|
+
# validates_acceptance_of :license_agreement, :accept => "1"
|
57
|
+
# validates_acceptance_of :terms_accepted, :allow_nil => false
|
57
58
|
#
|
58
59
|
# # a call to valid? will return false unless:
|
59
60
|
# # license_agreement is nil or "1"
|
60
61
|
# # and
|
61
62
|
# # terms_accepted is one of ["1", 1, "true", true, "t"]
|
62
63
|
#
|
63
|
-
def
|
64
|
+
def validates_acceptance_of(*fields)
|
64
65
|
opts = opts_from_validator_args(fields)
|
65
|
-
add_validator_to_context(opts, fields, DataMapper::
|
66
|
+
add_validator_to_context(opts, fields, DataMapper::Validations::AcceptanceValidator)
|
66
67
|
end
|
67
68
|
|
69
|
+
deprecate :validates_is_accepted, :validates_acceptance_of
|
70
|
+
|
68
71
|
end # module ValidatesIsAccepted
|
69
|
-
end # module
|
72
|
+
end # module Validations
|
70
73
|
end # module DataMapper
|