-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathsolid-process-1.rb
60 lines (45 loc) · 1.28 KB
/
solid-process-1.rb
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
class User::Registration < Solid::Process
input do
attribute :email, :string
attribute :password, :string
attribute :password_confirmation, :string
end
def call(attributes)
rollback_on_failure {
Given(attributes)
.and_then(:create_user)
.and_then(:create_user_account)
.and_then(:create_user_inbox)
.and_then(:create_user_token)
}
.and_then(:send_email_confirmation)
.and_expose(:user_registered, [:user])
end
private
def create_user(email:, password:, password_confirmation:, **)
user = User.create(email:, password:, password_confirmation:)
return Continue(user:) if user.persisted?
input.errors.merge!(user.errors)
Failure(:invalid_input, input:)
end
def create_user_account(user:, **)
account = Account.create!(uuid: SecureRandom.uuid)
account.memberships.create!(user:, role: :owner)
Continue(account:)
end
def create_user_inbox(account:, **)
account.task_lists.inbox.create!
Continue()
end
def create_user_token(user:, **)
user.create_token!
Continue()
end
def send_email_confirmation(user:, **)
UserMailer.with(
user:,
token: user.generate_token_for(:email_confirmation)
).email_confirmation.deliver_later
Continue()
end
end