Class: Account::Service::Lock

Inherits:
Object
  • Object
show all
Defined in:
app/models/aikotoba/account/service/lock.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(account:) ⇒ Lock

Returns a new instance of Lock.



17
18
19
# File 'app/models/aikotoba/account/service/lock.rb', line 17

def initialize(account:)
  @account = 
end

Class Method Details

.create_unlock_token!(account:, notify: false) ⇒ Object



13
14
15
# File 'app/models/aikotoba/account/service/lock.rb', line 13

def self.create_unlock_token!(account:, notify: false)
  new(account: ).create_unlock_token!(notify: notify)
end

.lock!(account:, notify: false) ⇒ Object



5
6
7
# File 'app/models/aikotoba/account/service/lock.rb', line 5

def self.lock!(account:, notify: false)
  new(account: ).lock!(notify: notify)
end

.unlock!(account:) ⇒ Object



9
10
11
# File 'app/models/aikotoba/account/service/lock.rb', line 9

def self.unlock!(account:)
  new(account: ).unlock!
end

Instance Method Details

#create_unlock_token!(notify:) ⇒ Object



35
36
37
38
39
40
# File 'app/models/aikotoba/account/service/lock.rb', line 35

def create_unlock_token!(notify:)
  ActiveRecord::Base.transaction do
    @account.build_unlock_token.save!
    @account.unlock_token.notify if notify
  end
end

#lock!(notify:) ⇒ Object



21
22
23
24
25
26
# File 'app/models/aikotoba/account/service/lock.rb', line 21

def lock!(notify:)
  ActiveRecord::Base.transaction do
    @account.lock!
    create_unlock_token!(notify: notify)
  end
end

#unlock!Object



28
29
30
31
32
33
# File 'app/models/aikotoba/account/service/lock.rb', line 28

def unlock!
  ActiveRecord::Base.transaction do
    @account.unlock!
    @account.unlock_token&.destroy!
  end
end