-
Notifications
You must be signed in to change notification settings - Fork 46
/
create_account.rb
47 lines (40 loc) · 1.39 KB
/
create_account.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
# Initialize and configure external dependencies for an Account
class CreateAccount
attr_reader :account
##
# @param [Account]
def initialize(account)
@account = account
end
# @return [Boolean] true if save and jobs spawning were successful
def save
account.save && create_external_resources ? true : false
end
# `Apartment::Tenant.create` calls the DB adapter's `switch`, which we have a hook into
# via an initializer. In our hook we do `account.switch!` and that requires a well-formed
# Account (i.e. creation steps complete, endpoints populated). THEREFORE, `create_tenant`
# must be called *after* all external resources are provisioned.
def create_external_resources
create_account_inline && create_tenant
end
##
# Create the apartment database tenant and initialize it with seed data
def create_tenant
Apartment::Tenant.create(account.tenant) do
initialize_account_data
account.switch do
AdminSet.find_or_create_default_admin_set_id
end
end
end
# Sacrifing idempotency of our account creation jobs here to reflect
# the dependency that exists between creating endpoints,
# specifically Solr and Fedora, and creation of the default Admin Set.
def create_account_inline
CreateAccountInlineJob.perform_now(account)
end
private
def initialize_account_data
Site.update(account: account)
end
end