summaryrefslogtreecommitdiff
path: root/users/app/models/email.rb
blob: 0745fda9293002838de7db9cf4a6ea42d85e24bd (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
class Email
  include CouchRest::Model::Embeddable

  property :email, String

  validates :email,
    :format => { :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/, :message => "needs to be a valid email address"}

  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?(String) ? self.email == other : super
  end

  def to_param
    email
  end
end