summaryrefslogtreecommitdiff
path: root/users/app/models/local_email.rb
blob: c1f7c1189453f295fb5e0b438d9250517f0ecc9c (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
36
37
38
39
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 handle
    gsub(/@#{domain}/i, '')
  end

  def domain
    LocalEmail.domain
  end

  protected

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

end