dm-validations 1.1.0 → 1.2.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. data/Gemfile +8 -8
  2. data/Rakefile +2 -2
  3. data/VERSION +1 -1
  4. data/dm-validations.gemspec +29 -139
  5. data/lib/dm-validations.rb +51 -103
  6. data/lib/dm-validations/auto_validate.rb +104 -61
  7. data/lib/dm-validations/context.rb +66 -0
  8. data/lib/dm-validations/contextual_validators.rb +164 -53
  9. data/lib/dm-validations/formats/email.rb +41 -23
  10. data/lib/dm-validations/formats/url.rb +6 -1
  11. data/lib/dm-validations/support/object.rb +13 -0
  12. data/lib/dm-validations/validation_errors.rb +27 -19
  13. data/lib/dm-validations/validators/absent_field_validator.rb +11 -11
  14. data/lib/dm-validations/validators/acceptance_validator.rb +15 -13
  15. data/lib/dm-validations/validators/block_validator.rb +12 -11
  16. data/lib/dm-validations/validators/confirmation_validator.rb +23 -16
  17. data/lib/dm-validations/validators/format_validator.rb +45 -23
  18. data/lib/dm-validations/validators/generic_validator.rb +85 -38
  19. data/lib/dm-validations/validators/length_validator.rb +61 -26
  20. data/lib/dm-validations/validators/method_validator.rb +13 -17
  21. data/lib/dm-validations/validators/numeric_validator.rb +35 -35
  22. data/lib/dm-validations/validators/primitive_validator.rb +11 -12
  23. data/lib/dm-validations/validators/required_field_validator.rb +11 -13
  24. data/lib/dm-validations/validators/uniqueness_validator.rb +15 -14
  25. data/lib/dm-validations/validators/within_validator.rb +30 -12
  26. data/spec/fixtures/bill_of_landing.rb +5 -0
  27. data/spec/fixtures/llama_spaceship.rb +15 -0
  28. data/spec/integration/automatic_validation/custom_messages_for_inferred_validation_spec.rb +10 -0
  29. data/spec/integration/automatic_validation/disabling_inferred_validation_spec.rb +8 -0
  30. data/spec/integration/automatic_validation/inferred_length_validation_spec.rb +8 -0
  31. data/spec/integration/automatic_validation/inferred_uniqueness_validation_spec.rb +6 -2
  32. data/spec/integration/automatic_validation/inferred_within_validation_spec.rb +6 -0
  33. data/spec/integration/datamapper_models/association_validation_spec.rb +5 -2
  34. data/spec/integration/dirty_attributes/dirty_attributes_spec.rb +13 -0
  35. data/spec/integration/format_validator/email_format_validator_spec.rb +13 -5
  36. data/spec/integration/format_validator/url_format_validator_spec.rb +28 -2
  37. data/spec/integration/required_field_validator/association_spec.rb +5 -1
  38. data/spec/public/resource_spec.rb +2 -2
  39. data/spec/spec_helper.rb +1 -1
  40. data/spec/unit/contextual_validators/emptiness_spec.rb +10 -10
  41. data/spec/unit/contextual_validators/execution_spec.rb +4 -4
  42. data/spec/unit/validators/within_validator_spec.rb +23 -0
  43. metadata +81 -146
  44. data/lib/dm-validations/support/context.rb +0 -93
@@ -7,7 +7,12 @@ module DataMapper
7
7
 
8
8
  def self.included(base)
9
9
  DataMapper::Validations::FormatValidator::FORMATS.merge!(
10
- :email_address => [ EmailAddress, lambda { |field, value| '%s is not a valid email address'.t(value) }]
10
+ :email_address => [
11
+ EmailAddress,
12
+ lambda { |field, value|
13
+ '%s is not a valid email address'.t(value)
14
+ }
15
+ ]
11
16
  )
12
17
  end
13
18
 
@@ -17,28 +22,41 @@ module DataMapper
17
22
  # 99% of the time you do not want to allow these email addresses
18
23
  # in a public web application.
19
24
  EmailAddress = begin
20
- alpha = "a-zA-Z\\p{Lu}\\p{Ll}" # Alpha characters, changed from RFC2822 to include unicode chars
21
- digit = "0-9"
22
- atext = "[#{alpha}#{digit}\!\#\$\%\&\'\*+\/\=\?\^\_\`\{\|\}\~\-]"
23
- dot_atom_text = "#{atext}+([.]#{atext}*)+" # Last char changed from * to +
24
- dot_atom = "#{dot_atom_text}"
25
- no_ws_ctl = "\\x01-\\x08\\x11\\x12\\x14-\\x1f\\x7f"
26
- qtext = "[^#{no_ws_ctl}\\x0d\\x22\\x5c]" # Non-whitespace, non-control character except for \ and "
27
- text = "[\\x01-\\x09\\x11\\x12\\x14-\\x7f]"
28
- quoted_pair = "(\\x5c#{text})"
29
- qcontent = "(?:#{qtext}|#{quoted_pair})"
30
- quoted_string = "[\"]#{qcontent}+[\"]"
31
- atom = "#{atext}+"
32
- word = "(?:#{atom}|#{quoted_string})"
33
- obs_local_part = "#{word}([.]#{word})*"
34
- local_part = "(?:#{dot_atom}|#{quoted_string}|#{obs_local_part})"
35
- dtext = "[#{no_ws_ctl}\\x21-\\x5a\\x5e-\\x7e]"
36
- dcontent = "(?:#{dtext}|#{quoted_pair})"
37
- domain_literal = "\\[#{dcontent}+\\]"
38
- obs_domain = "#{atom}([.]#{atom})+" # Last char changed from * to +
39
- domain = "(?:#{dot_atom}|#{domain_literal}|#{obs_domain})"
40
- addr_spec = "#{local_part}\@#{domain}"
41
- pattern = /^#{addr_spec}$/u
25
+ if (RUBY_VERSION == '1.9.2' && RUBY_ENGINE == 'jruby' && JRUBY_VERSION <= '1.6.3') || RUBY_VERSION == '1.9.3'
26
+ # There is an obscure bug in jruby 1.6 that prevents matching
27
+ # on unicode properties here. Remove this logic branch once
28
+ # a stable jruby release fixes this.
29
+ #
30
+ # http://jira.codehaus.org/browse/JRUBY-5622
31
+ #
32
+ # There is a similar bug in preview releases of 1.9.3
33
+ #
34
+ # http://redmine.ruby-lang.org/issues/5126
35
+ letter = 'a-zA-Z'
36
+ else
37
+ letter = 'a-zA-Z\p{L}' # Changed from RFC2822 to include unicode chars
38
+ end
39
+ digit = '0-9'
40
+ atext = "[#{letter}#{digit}\!\#\$\%\&\'\*+\/\=\?\^\_\`\{\|\}\~\-]"
41
+ dot_atom_text = "#{atext}+([.]#{atext}*)+"
42
+ dot_atom = dot_atom_text
43
+ no_ws_ctl = '\x01-\x08\x11\x12\x14-\x1f\x7f'
44
+ qtext = "[^#{no_ws_ctl}\\x0d\\x22\\x5c]" # Non-whitespace, non-control character except for \ and "
45
+ text = '[\x01-\x09\x11\x12\x14-\x7f]'
46
+ quoted_pair = "(\\x5c#{text})"
47
+ qcontent = "(?:#{qtext}|#{quoted_pair})"
48
+ quoted_string = "[\"]#{qcontent}+[\"]"
49
+ atom = "#{atext}+"
50
+ word = "(?:#{atom}|#{quoted_string})"
51
+ obs_local_part = "#{word}([.]#{word})*"
52
+ local_part = "(?:#{dot_atom}|#{quoted_string}|#{obs_local_part})"
53
+ dtext = "[#{no_ws_ctl}\\x21-\\x5a\\x5e-\\x7e]"
54
+ dcontent = "(?:#{dtext}|#{quoted_pair})"
55
+ domain_literal = "\\[#{dcontent}+\\]"
56
+ obs_domain = "#{atom}([.]#{atom})+"
57
+ domain = "(?:#{dot_atom}|#{domain_literal}|#{obs_domain})"
58
+ addr_spec = "#{local_part}\@#{domain}"
59
+ pattern = /\A#{addr_spec}\z/u
42
60
  end
43
61
 
44
62
  end # module Email
@@ -7,7 +7,12 @@ module DataMapper
7
7
 
8
8
  def self.included(base)
9
9
  DataMapper::Validations::FormatValidator::FORMATS.merge!(
10
- :url => [ Url, lambda { |field, value| '%s is not a valid URL'.t(value) }]
10
+ :url => [
11
+ Url,
12
+ lambda { |field, value|
13
+ '%s is not a valid URL'.t(value)
14
+ }
15
+ ]
11
16
  )
12
17
  end
13
18
 
@@ -1,4 +1,17 @@
1
1
  class Object
2
+ # If receiver is callable, calls it and returns result.
3
+ # If not, just returns receiver itself
4
+ #
5
+ # @return [Object]
6
+ # @api private
7
+ def try_call(*args)
8
+ if self.respond_to?(:call)
9
+ self.call(*args)
10
+ else
11
+ self
12
+ end
13
+ end
14
+
2
15
  def validatable?
3
16
  false
4
17
  end
@@ -1,7 +1,5 @@
1
1
  module DataMapper
2
2
  module Validations
3
-
4
- ##
5
3
  #
6
4
  # @author Guy van den Berg
7
5
  # @since 0.9
@@ -56,24 +54,31 @@ module DataMapper
56
54
  errors.clear
57
55
  end
58
56
 
59
- # Add a validation error. Use the field_name :general if the errors does
60
- # not apply to a specific field of the Resource.
57
+ # Add a validation error. Use the field_name :general if the errors
58
+ # does not apply to a specific field of the Resource.
59
+ #
60
+ # @param [Symbol] field_name
61
+ # The name of the field that caused the error
61
62
  #
62
- # @param [Symbol] field_name the name of the field that caused the error
63
- # @param [String] message the message to add
63
+ # @param [String] message
64
+ # The message to add
64
65
  def add(field_name, message)
65
66
  # see 6abe8fff in extlib, but don't enforce
66
67
  # it unless Edge version is installed
67
68
  if message.respond_to?(:try_call)
68
-
69
69
  # DM resource
70
- message = if resource.respond_to?(:model) && resource.model.respond_to?(:properties)
71
- message.try_call(resource, resource.model.properties[field_name])
72
- else
73
- # pure Ruby object
74
- message.try_call(resource)
75
- end
70
+ message = if (resource.respond_to?(:model) &&
71
+ resource.model.respond_to?(:properties))
72
+ message.try_call(
73
+ resource,
74
+ resource.model.properties[field_name]
75
+ )
76
+ else
77
+ # pure Ruby object
78
+ message.try_call(resource)
79
+ end
76
80
  end
81
+
77
82
  (errors[field_name] ||= []) << message
78
83
  end
79
84
 
@@ -86,18 +91,20 @@ module DataMapper
86
91
 
87
92
  # Return validation errors for a particular field_name.
88
93
  #
89
- # @param [Symbol] field_name the name of the field you want an error for
94
+ # @param [Symbol] field_name
95
+ # The name of the field you want an error for.
96
+ #
90
97
  # @return [Array<DataMapper::Validations::Error>]
91
- # array of validation errors or empty array, if there are no errors on given field
98
+ # Array of validation errors or empty array, if there are no errors
99
+ # on given field
92
100
  def on(field_name)
93
101
  errors_for_field = errors[field_name]
94
102
  DataMapper::Ext.blank?(errors_for_field) ? nil : errors_for_field.uniq
95
103
  end
96
104
 
97
105
  def each
98
- errors.map.each do |k, v|
99
- next if DataMapper::Ext.blank?(v)
100
- yield(v)
106
+ errors.each_value do |v|
107
+ yield(v) unless DataMapper::Ext.blank?(v)
101
108
  end
102
109
  end
103
110
 
@@ -114,12 +121,13 @@ module DataMapper
114
121
  end
115
122
 
116
123
  def [](property_name)
117
- if property_errors = errors[property_name.to_sym]
124
+ if (property_errors = errors[property_name.to_sym])
118
125
  property_errors
119
126
  end
120
127
  end
121
128
 
122
129
  private
130
+
123
131
  def errors
124
132
  @errors
125
133
  end
@@ -1,29 +1,31 @@
1
1
  module DataMapper
2
2
  module Validations
3
-
4
- ##
5
3
  #
6
4
  # @author Guy van den Berg
7
5
  # @since 0.9
8
6
  class AbsenceValidator < GenericValidator
7
+
9
8
  def call(target)
10
9
  value = target.validation_property_value(field_name)
11
10
  return true if DataMapper::Ext.blank?(value)
12
11
 
13
- error_message = self.options[:message] || ValidationErrors.default_error_message(:absent, field_name)
14
- add_error(target, error_message, field_name)
12
+ error_message = (
13
+ self.options[:message] || ValidationErrors.default_error_message(
14
+ :absent, field_name
15
+ )
16
+ )
15
17
 
18
+ add_error(target, error_message, field_name)
16
19
  false
17
20
  end
21
+
18
22
  end # class AbsenceValidator
19
23
 
20
24
  module ValidatesAbsence
21
-
22
25
  extend Deprecate
23
26
 
24
- ##
25
- # Validates that the specified attribute is "blank" via the attribute's
26
- # #blank? method.
27
+ # Validates that the specified attribute is "blank" via the
28
+ # attribute's #blank? method.
27
29
  #
28
30
  # @note
29
31
  # dm-core's support lib adds the #blank? method to many classes,
@@ -47,12 +49,10 @@ module DataMapper
47
49
  # end
48
50
  #
49
51
  def validates_absence_of(*fields)
50
- opts = opts_from_validator_args(fields)
51
- add_validator_to_context(opts, fields, DataMapper::Validations::AbsenceValidator)
52
+ validators.add(AbsenceValidator, *fields)
52
53
  end
53
54
 
54
55
  deprecate :validates_absent, :validates_absence_of
55
-
56
56
  end # module ValidatesAbsent
57
57
  end # module Validations
58
58
  end # module DataMapper
@@ -1,8 +1,5 @@
1
1
  module DataMapper
2
2
  module Validations
3
-
4
- ##
5
- #
6
3
  # @author Martin Kihlgren
7
4
  # @since 0.9
8
5
  class AcceptanceValidator < GenericValidator
@@ -19,7 +16,11 @@ module DataMapper
19
16
  def call(target)
20
17
  return true if valid?(target)
21
18
 
22
- error_message = @options[:message] || ValidationErrors.default_error_message(:accepted, field_name)
19
+ error_message = (
20
+ @options[:message] || ValidationErrors.default_error_message(
21
+ :accepted, field_name
22
+ )
23
+ )
23
24
  add_error(target, error_message, field_name)
24
25
 
25
26
  false
@@ -36,20 +37,22 @@ module DataMapper
36
37
  def allow_nil?(value)
37
38
  @options[:allow_nil] && value.nil?
38
39
  end
40
+
39
41
  end # class AcceptanceValidator
40
42
 
41
43
  module ValidatesAcceptance
42
44
  extend Deprecate
43
45
 
44
- ##
45
- # Validates that the attributes's value is in the set of accepted values.
46
+ # Validates that the attributes's value is in the set of accepted
47
+ # values.
48
+ #
49
+ # @option [Boolean] :allow_nil (true)
50
+ # true if nil is allowed, false if not allowed.
46
51
  #
47
- # @option :allow_nil<Boolean> true if nil is allowed, false if not
48
- # allowed. Default is true.
49
- # @option :accept<Array> a list of accepted values.
50
- # Default are ["1", 1, "true", true, "t"]).
52
+ # @option [Array] :accept (["1", 1, "true", true, "t"])
53
+ # A list of accepted values.
51
54
  #
52
- # @example [Usage]
55
+ # @example Usage
53
56
  # require 'dm-validations'
54
57
  #
55
58
  # class Page
@@ -66,8 +69,7 @@ module DataMapper
66
69
  # # terms_accepted is one of ["1", 1, "true", true, "t"]
67
70
  #
68
71
  def validates_acceptance_of(*fields)
69
- opts = opts_from_validator_args(fields)
70
- add_validator_to_context(opts, fields, DataMapper::Validations::AcceptanceValidator)
72
+ validators.add(AcceptanceValidator, *fields)
71
73
  end
72
74
 
73
75
  deprecate :validates_is_accepted, :validates_acceptance_of
@@ -1,13 +1,8 @@
1
1
  module DataMapper
2
2
  module Validations
3
-
4
- ##
5
- #
6
3
  # @author teamon
7
4
  # @since 0.9
8
5
  module ValidatesWithBlock
9
-
10
- ##
11
6
  # Validate using the given block. The block given needs to return:
12
7
  # [result::<Boolean>, Error Message::<String>]
13
8
  #
@@ -46,15 +41,21 @@ module DataMapper
46
41
  def validates_with_block(*fields, &block)
47
42
  @__validates_with_block_count ||= 0
48
43
  @__validates_with_block_count += 1
44
+
49
45
  # create method and pass it to MethodValidator
50
- raise ArgumentError.new('You need to pass a block to validates_with_block method') unless block_given?
46
+ unless block_given?
47
+ raise ArgumentError, 'You need to pass a block to validates_with_block method'
48
+ end
49
+
51
50
  method_name = "__validates_with_block_#{@__validates_with_block_count}".to_sym
52
- define_method(method_name, block)
53
- opts = opts_from_validator_args(fields)
54
- opts[:method] = method_name
55
- add_validator_to_context(opts, fields.empty? ? [method_name] : fields, DataMapper::Validations::MethodValidator)
56
- end
51
+ define_method(method_name, &block)
52
+
53
+ options = fields.last.is_a?(Hash) ? fields.last.pop.dup : {}
54
+ options[:method] = method_name
55
+ fields = [method_name] if fields.empty?
57
56
 
57
+ validators.add(MethodValidator, *fields + [options])
58
+ end
58
59
  end # module ValidatesWithMethod
59
60
  end # module Validations
60
61
  end # module DataMapper
@@ -1,9 +1,6 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  module DataMapper
3
3
  module Validations
4
-
5
- ##
6
- #
7
4
  # @author Guy van den Berg
8
5
  # @since 0.9
9
6
  class ConfirmationValidator < GenericValidator
@@ -13,13 +10,19 @@ module DataMapper
13
10
 
14
11
  set_optional_by_default
15
12
 
16
- @confirm_field_name = (options[:confirm] || "#{field_name}_confirmation").to_sym
13
+ @confirm_field_name = (
14
+ options[:confirm] || "#{field_name}_confirmation"
15
+ ).to_sym
17
16
  end
18
17
 
19
18
  def call(target)
20
19
  return true if valid?(target)
21
20
 
22
- error_message = @options[:message] || ValidationErrors.default_error_message(:confirmation, field_name)
21
+ error_message = (
22
+ @options[:message] || ValidationErrors.default_error_message(
23
+ :confirmation, field_name
24
+ )
25
+ )
23
26
  add_error(target, error_message, field_name)
24
27
 
25
28
  false
@@ -38,23 +41,28 @@ module DataMapper
38
41
  confirm_value = target.instance_variable_get("@#{@confirm_field_name}")
39
42
  value == confirm_value
40
43
  end
44
+
41
45
  end # class ConfirmationValidator
42
46
 
43
47
  module ValidatesConfirmation
44
48
  extend Deprecate
45
49
 
46
50
  ##
47
- # Validates that the given attribute is confirmed by another attribute.
48
- # A common use case scenario is when you require a user to confirm their
49
- # password, for which you use both password and password_confirmation
50
- # attributes.
51
+ # Validates that the given attribute is confirmed by another
52
+ # attribute. A common use case scenario is when you require a user to
53
+ # confirm their password, for which you use both password and
54
+ # password_confirmation attributes.
55
+ #
56
+ # @option [Boolean] :allow_nil (true)
57
+ # true or false.
58
+ #
59
+ # @option [Boolean] :allow_blank (true)
60
+ # true or false.
51
61
  #
52
- # @option :allow_nil<Boolean> true/false (default is true)
53
- # @option :allow_blank<Boolean> true/false (default is true)
54
- # @option :confirm<Symbol> the attribute that you want to validate
55
- # against (default is firstattr_confirmation)
62
+ # @option [Symbol] :confirm (firstattr_confirmation)
63
+ # The attribute that you want to validate against.
56
64
  #
57
- # @example [Usage]
65
+ # @example Usage
58
66
  # require 'dm-validations'
59
67
  #
60
68
  # class Page
@@ -74,8 +82,7 @@ module DataMapper
74
82
  # # email == email_repeated
75
83
  #
76
84
  def validates_confirmation_of(*fields)
77
- opts = opts_from_validator_args(fields)
78
- add_validator_to_context(opts, fields, DataMapper::Validations::ConfirmationValidator)
85
+ validators.add(ConfirmationValidator, *fields)
79
86
  end
80
87
 
81
88
  deprecate :validates_is_confirmed, :validates_confirmation_of
@@ -8,13 +8,12 @@ module DataMapper
8
8
  module Validations
9
9
  class UnknownValidationFormat < ::ArgumentError; end
10
10
 
11
- ##
12
- #
13
11
  # @author Guy van den Berg
14
12
  # @since 0.9
15
13
  class FormatValidator < GenericValidator
16
14
 
17
15
  FORMATS = {}
16
+
18
17
  include DataMapper::Validations::Format::Email
19
18
  include DataMapper::Validations::Format::Url
20
19
 
@@ -29,9 +28,17 @@ module DataMapper
29
28
 
30
29
  value = target.validation_property_value(field_name)
31
30
 
32
- error_message = @options[:message] || ValidationErrors.default_error_message(:invalid, field_name)
33
- add_error(target, error_message.try_call(humanized_field_name, value), field_name)
34
-
31
+ error_message = (
32
+ @options[:message] || ValidationErrors.default_error_message(
33
+ :invalid, field_name
34
+ )
35
+ )
36
+
37
+ add_error(
38
+ target,
39
+ error_message.try_call(humanized_field_name, value),
40
+ field_name
41
+ )
35
42
  false
36
43
  end
37
44
 
@@ -43,37 +50,54 @@ module DataMapper
43
50
 
44
51
  validation = @options[:as] || @options[:with]
45
52
 
46
- raise "No such predefined format '#{validation}'" if validation.is_a?(Symbol) && !FORMATS.has_key?(validation)
47
- validator = validation.is_a?(Symbol) ? FORMATS[validation][0] : validation
53
+ if validation.is_a?(Symbol) && !FORMATS.has_key?(validation)
54
+ raise("No such predefined format '#{validation}'")
55
+ end
56
+
57
+ validator = if validation.is_a?(Symbol)
58
+ FORMATS[validation][0]
59
+ else
60
+ validation
61
+ end
48
62
 
49
63
  case validator
50
64
  when Proc then validator.call(value)
51
- when Regexp then (value.kind_of?(Numeric) ? value.to_s : value) =~ validator
65
+ when Regexp then value ? value.to_s =~ validator : false
52
66
  else
53
- raise UnknownValidationFormat, "Can't determine how to validate #{target.class}##{field_name} with #{validator.inspect}"
67
+ raise(UnknownValidationFormat, "Can't determine how to validate #{target.class}##{field_name} with #{validator.inspect}")
54
68
  end
69
+ rescue Encoding::CompatibilityError
70
+ # This is to work around a bug in jruby - see formats/email.rb
71
+ false
55
72
  end
56
- end # class FormatValidator
57
73
 
74
+ end # class FormatValidator
58
75
 
59
76
  module ValidatesFormat
60
77
  extend Deprecate
61
78
 
62
- ##
63
- # Validates that the attribute is in the specified format. You may use the
64
- # :as (or :with, it's an alias) option to specify the pre-defined format
65
- # that you want to validate against. You may also specify your own format
66
- # via a Proc or Regexp passed to the the :as or :with options.
79
+ # Validates that the attribute is in the specified format. You may
80
+ # use the :as (or :with, it's an alias) option to specify the
81
+ # pre-defined format that you want to validate against. You may also
82
+ # specify your own format via a Proc or Regexp passed to the the :as
83
+ # or :with options.
84
+ #
85
+ # @option [Boolean] :allow_nil (true)
86
+ # true or false.
87
+ #
88
+ # @option [Boolean] :allow_blank (true)
89
+ # true or false.
67
90
  #
68
- # @option :allow_nil<Boolean> true/false (default is true)
69
- # @option :allow_blank<Boolean> true/false (default is true)
70
- # @option :as<Format, Proc, Regexp> the pre-defined format, Proc or Regexp to validate against
71
- # @option :with<Format, Proc, Regexp> an alias for :as
91
+ # @option [Format, Proc, Regexp] :as
92
+ # The pre-defined format, Proc or Regexp to validate against.
93
+ #
94
+ # @option [Format, Proc, Regexp] :with
95
+ # An alias for :as.
72
96
  #
73
97
  # :email_address (format is specified in DataMapper::Validations::Format::Email - note that unicode emails will *not* be matched under MRI1.8.7)
74
98
  # :url (format is specified in DataMapper::Validations::Format::Url)
75
99
  #
76
- # @example [Usage]
100
+ # @example Usage
77
101
  # require 'dm-validations'
78
102
  #
79
103
  # class Page
@@ -91,12 +115,10 @@ module DataMapper
91
115
  # # zip_code is a string of 5 digits
92
116
  #
93
117
  def validates_format_of(*fields)
94
- opts = opts_from_validator_args(fields)
95
- add_validator_to_context(opts, fields, DataMapper::Validations::FormatValidator)
118
+ validators.add(FormatValidator, *fields)
96
119
  end
97
120
 
98
121
  deprecate :validates_format, :validates_format_of
99
-
100
122
  end # module ValidatesFormat
101
123
  end # module Validations
102
124
  end # module DataMapper