Class: Lita::Handlers::Customer

Inherits:
Handler
  • Object
show all
Defined in:
lib/lita/handlers/customer.rb

Overview

Handles all commands related to the customer

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.template_rootObject



8
9
10
# File 'lib/lita/handlers/customer.rb', line 8

def self.template_root
  File.expand_path('../../../templates', __dir__)
end

Instance Method Details

#add(response) ⇒ Object



58
59
60
61
62
63
# File 'lib/lita/handlers/customer.rb', line 58

def add(response)
  interactor = Interactors::AddQuantity.new(self, response.match_data).perform
  template = :message
  message = { message: interactor.message }
  reply(template, message, response, interactor)
end

#add_all(response) ⇒ Object



65
66
67
68
69
70
# File 'lib/lita/handlers/customer.rb', line 65

def add_all(response)
  interactor = Interactors::AddAll.new(self, response.match_data).perform
  template = :message
  message = { message: interactor.message }
  reply(template, message, response, interactor)
end

#change_value(response) ⇒ Object



51
52
53
54
55
56
# File 'lib/lita/handlers/customer.rb', line 51

def change_value(response)
  interactor = Interactors::ChangeValue.new(self, response.match_data).perform
  template = :message
  message = { message: interactor.message }
  reply(template, message, response, interactor)
end

#delete_customer(response) ⇒ Object



79
80
81
82
83
84
# File 'lib/lita/handlers/customer.rb', line 79

def delete_customer(response)
  interactor = Interactors::DeleteCustomer.new(self, response.match_data).perform
  template = :message
  message = { message: interactor.message }
  reply(template, message, response, interactor)
end

#inscribe(response) ⇒ Object

Callbacks



44
45
46
47
48
49
# File 'lib/lita/handlers/customer.rb', line 44

def inscribe(response)
  interactor = Interactors::InscribeCustomer.new(self, response.match_data).perform
  template = :message
  message = { message: interactor.message }
  reply(template, message, response, interactor)
end

#reply(template, message, response, interactor) ⇒ Object



86
87
88
89
90
91
92
# File 'lib/lita/handlers/customer.rb', line 86

def reply(template, message, response, interactor)
  unless interactor.success?
    template = :error
    message = { error: interactor.error }
  end
  response.reply(render_template(template, message))
end

#reset(response) ⇒ Object



72
73
74
75
76
77
# File 'lib/lita/handlers/customer.rb', line 72

def reset(response)
  interactor = Interactors::ResetQuantity.new(self, response.match_data).perform
  template = :message
  message = { message: interactor.message }
  reply(template, message, response, interactor)
end