Skip to content

Commit 766de52

Browse files
author
Ben Lavender
committed
support chatops error responses
1 parent 9f003b0 commit 766de52

2 files changed

Lines changed: 12 additions & 11 deletions

File tree

lib/chatops/controller.rb

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ def list
1414
render :json => {
1515
namespace: self.class.chatops_namespace,
1616
help: self.class.chatops_help,
17+
error_response: self.class.chatops_error_response,
1718
methods: chatops }
1819
end
1920

@@ -104,18 +105,16 @@ def chatop(method_name, regex, help, &block)
104105
define_method method_name, &block
105106
end
106107

107-
def chatops_namespace(namespace = nil)
108-
if namespace.present?
109-
@chatops_namespace = namespace
108+
%w{namespace help error_response}.each do |setting|
109+
method_name = "chatops_#{setting}".to_sym
110+
variable_name = "@#{method_name}".to_sym
111+
define_method method_name do |*args|
112+
assignment = args.first
113+
if assignment.present?
114+
instance_variable_set variable_name, assignment
115+
end
116+
instance_variable_get variable_name.to_sym
110117
end
111-
@chatops_namespace
112-
end
113-
114-
def chatops_help(help = nil)
115-
if help.present?
116-
@chatops_help = help
117-
end
118-
@chatops_help
119118
end
120119

121120
def chatops

spec/lib/chatops/controller_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
include ChatOps::Controller
66
chatops_namespace :test
77
chatops_help "ChatOps of and relating to testing"
8+
chatops_error_response "Try checking haystack?"
89

910
before_filter :ensure_app_given, :only => [:wcid]
1011

@@ -92,6 +93,7 @@ def ensure_app_given
9293
expect(json_response).to eq({
9394
"namespace" => "test",
9495
"help" => "ChatOps of and relating to testing",
96+
"error_response" => "Try checking haystack?",
9597
"methods" => {
9698
"wcid" => {
9799
"help" => "where can i deploy?",

0 commit comments

Comments
 (0)