Total Complexity | 5 |
Total Lines | 20 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | class User < ActiveRecord::Base |
||
2 | validates :name, :phone, :presence => true, :uniqueness => true |
||
3 | validate :phone_plausible |
||
4 | |||
5 | def phone_plausible |
||
6 | errors.add(:phone, :invalid) if phone.present? && !Phony.plausible?(phone) |
||
7 | end |
||
8 | |||
9 | def phone=(value) |
||
10 | Phony.plausible?(value) ? super(Phony.normalize(value)) : super(value) |
||
11 | end |
||
12 | |||
13 | after_create do |
||
14 | ## This would send SMS instantly and slow app down... |
||
15 | # UserTexter.welcome(self).deliver_now |
||
16 | |||
17 | ## ...so let's use shiny, async ActiveJob instead |
||
18 | UserTexter.welcome(self).deliver_later |
||
19 | end |
||
20 | end |
||
21 |