Class: TermsOfUse::Decliner

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user_account:, version:) ⇒ Decliner

Returns a new instance of Decliner.



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

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

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

Instance Attribute Details

#icnObject (readonly)

Returns the value of attribute icn.



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

def icn
  @icn
end

#user_accountObject (readonly)

Returns the value of attribute user_account.



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

def 
  @user_account
end

#versionObject (readonly)

Returns the value of attribute version.



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

def version
  @version
end

Instance Method Details

#log_and_raise_decliner_error(error) ⇒ Object (private)



46
47
48
49
# File 'app/services/terms_of_use/decliner.rb', line 46

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

#perform!Object



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

def perform!
  terms_of_use_agreement.declined!

  
  Logger.new(terms_of_use_agreement:).perform

  terms_of_use_agreement
rescue ActiveRecord::RecordInvalid => e
  log_and_raise_decliner_error(e)
end

#terms_of_use_agreementObject (private)



37
38
39
# File 'app/services/terms_of_use/decliner.rb', line 37

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

#update_sign_up_serviceObject (private)



41
42
43
44
# File 'app/services/terms_of_use/decliner.rb', line 41

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