summaryrefslogtreecommitdiff
path: root/users/app/models/local_email.rb
blob: 6303bb6edf7a3a4707616718b64eaa8cc685bca8 (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
29
30
31
32
33
34
35
class LocalEmail < Email


  def self.domain
    APP_CONFIG[:domain]
  end

  validates :email,
    :format => {
      :with => /@#{domain}\Z/i,
      :message => "needs to end in @#{domain}"
    }

  def initialize(s)
    super
    append_domain_if_needed
  end

  def to_key
    [handle]
  end

  def domain
    LocalEmail.domain
  end

  protected

  def append_domain_if_needed
    unless self.index('@')
      self << '@' + domain
    end
  end

end