blob: 904acb9c70f17af0d9538017f697fb7abedc18fa (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
module Email
extend ActiveSupport::Concern
included do
validates :email,
:format => {
:with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/,
:message => "needs to be a valid email address"
}
end
def initialize(attributes = nil, &block)
attributes = {:email => attributes} if attributes.is_a? String
super(attributes, &block)
end
def to_s
email
end
def ==(other)
other.is_a?(Email) ? self.email == other.email : self.email == other
end
def to_param
email
end
end
|