Class: TermsOfUse::Acceptor

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Validations
Defined in:
app/services/terms_of_use/acceptor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user_account:, version:, sync: false) ⇒ Acceptor

Returns a new instance of Acceptor.



14
15
16
17
18
19
20
21
22
23
# File 'app/services/terms_of_use/acceptor.rb', line 14

def initialize(user_account:, version:, sync: false)
  @user_account = 
  @version = version
  @sync = sync
  @icn = &.icn

  validate!
rescue ActiveModel::ValidationError => e
  log_and_raise_acceptor_error(e)
end

Instance Attribute Details

#icnObject (readonly)

Returns the value of attribute icn.



10
11
12
# File 'app/services/terms_of_use/acceptor.rb', line 10

def icn
  @icn
end

#syncObject (readonly)

Returns the value of attribute sync.



10
11
12
# File 'app/services/terms_of_use/acceptor.rb', line 10

def sync
  @sync
end

#user_accountObject (readonly)

Returns the value of attribute user_account.



10
11
12
# File 'app/services/terms_of_use/acceptor.rb', line 10

def 
  @user_account
end

#versionObject (readonly)

Returns the value of attribute version.



10
11
12
# File 'app/services/terms_of_use/acceptor.rb', line 10

def version
  @version
end

Instance Method Details

#log_and_raise_acceptor_error(error) ⇒ Object (private)



47
48
49
50
# File 'app/services/terms_of_use/acceptor.rb', line 47

def log_and_raise_acceptor_error(error)
  Rails.logger.error("[TermsOfUse] [Acceptor] Error: #{error.message}", { user_account_id: &.id })
  raise Errors::AcceptorError, error.message
end

#perform!Object



25
26
27
28
29
30
31
32
33
34
# File 'app/services/terms_of_use/acceptor.rb', line 25

def perform!
  terms_of_use_agreement.accepted!

  
  Logger.new(terms_of_use_agreement:).perform

  terms_of_use_agreement
rescue ActiveRecord::RecordInvalid, StandardError => e
  log_and_raise_acceptor_error(e)
end

#terms_of_use_agreementObject (private)



38
39
40
# File 'app/services/terms_of_use/acceptor.rb', line 38

def terms_of_use_agreement
  @terms_of_use_agreement ||= .terms_of_use_agreements.new(agreement_version: version)
end

#update_sign_up_serviceObject (private)



42
43
44
45
# File 'app/services/terms_of_use/acceptor.rb', line 42

def 
  Rails.logger.info('[TermsOfUse] [Acceptor] update_sign_up_service', { icn: })
  SignUpServiceUpdaterJob.set(sync:).perform_async(.id, version)
end