brodock-validates_as_email 0.7.0 → 0.7.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/CHANGELOG +3 -0
  2. data/README +1 -1
  3. data/lib/validates_as_email.rb +15 -0
  4. metadata +3 -3
data/CHANGELOG CHANGED
@@ -1,3 +1,6 @@
1
+ 0.7.1 - April 26th 2010
2
+ * Added support for allow_blank and documentation
3
+
1
4
  0.7.0 - April 24th 2010
2
5
  * Updated to support Sexy Validations on Rails 3
3
6
  * Requires Rails 3
data/README CHANGED
@@ -36,7 +36,7 @@ end
36
36
 
37
37
  class MyOtherClass < ActiveRecord::Base
38
38
  # will not accept addresses with a single part domain, e.g user@example
39
- validates_as_email :email, :message => 'Invalid Email Address', :allow_nil => true, :restrict_domain => true
39
+ validates_as_email :email, :message => 'Invalid Email Address', :allow_nil => true
40
40
  end
41
41
 
42
42
  Tests:
@@ -26,6 +26,7 @@ module ActiveModel
26
26
  def validate_each(record, attribute, value)
27
27
 
28
28
  return if options[:allow_nil] && value.nil?
29
+ return if options[:allow_blank] && value.blank?
29
30
 
30
31
  unless value =~ /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i
31
32
  record.errors[attribute] << (options[:message])
@@ -35,6 +36,20 @@ module ActiveModel
35
36
  end
36
37
 
37
38
  module ClassMethods
39
+
40
+ # Validates that the specified attribute is a valid email address.
41
+ #
42
+ # Configuration options:
43
+ # * <tt>:allow_nil</tt> - Attribute may be +nil+; skip validation.
44
+ # * <tt>:allow_blank</tt> - Attribute may be blank; skip validation.
45
+ # * <tt>:message</tt> - The error message to be displayed
46
+ # * <tt>:on</tt> - Specifies when this validation is active (default is <tt>:save</tt>, other options <tt>:create</tt>, <tt>:update</tt>).
47
+ # * <tt>:if</tt> - Specifies a method, proc or string to call to determine if the validation should
48
+ # occur (e.g. <tt>:if => :allow_validation</tt>, or <tt>:if => Proc.new { |user| user.signup_step > 2 }</tt>). The
49
+ # method, proc or string should return or evaluate to a true or false value.
50
+ # * <tt>:unless</tt> - Specifies a method, proc or string to call to determine if the validation should
51
+ # not occur (e.g. <tt>:unless => :skip_validation</tt>, or <tt>:unless => Proc.new { |user| user.signup_step <= 2 }</tt>). The
52
+ # method, proc or string should return or evaluate to a true or false value.
38
53
  def validates_as_email(*attr_names)
39
54
  validates_with EmailValidator, _merge_attributes(attr_names)
40
55
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 7
8
- - 0
9
- version: 0.7.0
8
+ - 2
9
+ version: 0.7.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Michal Zima
@@ -19,7 +19,7 @@ autorequire:
19
19
  bindir: bin
20
20
  cert_chain: []
21
21
 
22
- date: 2010-04-24 00:00:00 -03:00
22
+ date: 2010-05-02 00:00:00 -03:00
23
23
  default_executable:
24
24
  dependencies: []
25
25