Class: Users::RespondToTermsService

Inherits:
Object
  • Object
show all
Defined in:
app/services/users/respond_to_terms_service.rb

Instance Method Summary collapse

Constructor Details

#initialize(user, term) ⇒ RespondToTermsService

Returns a new instance of RespondToTermsService.



5
6
7
8
# File 'app/services/users/respond_to_terms_service.rb', line 5

def initialize(user, term)
  @user = user
  @term = term
end

Instance Method Details

#execute(accepted:) ⇒ Object

rubocop: disable CodeReuse/ActiveRecord



11
12
13
14
15
16
17
18
19
20
# File 'app/services/users/respond_to_terms_service.rb', line 11

def execute(accepted:)
  agreement = @user.term_agreements.find_or_initialize_by(term: @term)
  agreement.accepted = accepted

  if agreement.save
    store_accepted_term(accepted)
  end

  agreement
end