Class: Lita::Handlers::Pagerduty
- Inherits:
-
Handler
- Object
- Handler
- Lita::Handlers::Pagerduty
show all
- Defined in:
- lib/lita/handlers/pagerduty.rb
Constant Summary
collapse
- COMMANDS_PATH =
File.read("#{File.dirname(__FILE__)}/commands.yml")
- COMMANDS =
YAML.safe_load(COMMANDS_PATH)
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, message) ⇒ Object
23
24
25
26
27
28
29
|
# File 'lib/lita/handlers/pagerduty.rb', line 23
def method_missing(method, message)
super if COMMANDS.map { |i| i['method'] }.include? method
response = Object.const_get(
'Commands::' << method.to_s.split('_').map(&:capitalize).join
).send(:call, message, , store)
handle_response(message, response) if response
end
|
Instance Method Details
#handle_response(message, response) ⇒ Object
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/lita/handlers/pagerduty.rb', line 48
def handle_response(message, response)
message.reply case response
when String
response
when Hash
t response[:message], response[:params]
when Array
response.map { |item| t item[:message], item[:params] }
.join("\n")
end
end
|
35
36
37
38
39
40
41
42
|
# File 'lib/lita/handlers/pagerduty.rb', line 35
def
||= ::.new(
http,
config.api_key,
config.email,
config.teams
)
end
|
#respond_to_missing?(method, include_private = false) ⇒ Boolean
31
32
33
|
# File 'lib/lita/handlers/pagerduty.rb', line 31
def respond_to_missing?(method, include_private = false)
COMMANDS.map { |i| i['method'] }.include?(method) || super
end
|
#store ⇒ Object
44
45
46
|
# File 'lib/lita/handlers/pagerduty.rb', line 44
def store
@store ||= Store.new(redis)
end
|