diff options
author | Douwe Maan <douwe@selenight.nl> | 2016-08-17 18:58:44 -0500 |
---|---|---|
committer | Douwe Maan <douwe@selenight.nl> | 2016-08-17 18:58:44 -0500 |
commit | 3e7eeefc939f2ce5234e36684c00b8d1c7e1c7dc (patch) | |
tree | 203850462714f28ae4d88654d48bd2ac759f9967 /lib | |
parent | 8b8a4626c601a13683599fd1a127e2c502af38a3 (diff) | |
download | gitlab-ce-3e7eeefc939f2ce5234e36684c00b8d1c7e1c7dc.tar.gz |
Address feedback
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/slash_commands/command_definition.rb | 16 | ||||
-rw-r--r-- | lib/gitlab/slash_commands/extractor.rb | 17 |
2 files changed, 16 insertions, 17 deletions
diff --git a/lib/gitlab/slash_commands/command_definition.rb b/lib/gitlab/slash_commands/command_definition.rb index 641c92e77da..2ff8f4eddf0 100644 --- a/lib/gitlab/slash_commands/command_definition.rb +++ b/lib/gitlab/slash_commands/command_definition.rb @@ -6,11 +6,11 @@ module Gitlab def initialize(name, attributes = {}) @name = name - @aliases = attributes[:aliases] || [] - @description = attributes[:description] || '' - @params = attributes[:params] || [] - @condition_block = attributes[:condition_block] - @action_block = attributes[:action_block] + @aliases = attributes[:aliases] || [] + @description = attributes[:description] || '' + @params = attributes[:params] || [] + @condition_block = attributes[:condition_block] + @action_block = attributes[:action_block] end def all_names @@ -28,13 +28,13 @@ module Gitlab context.instance_exec(&condition_block) end - def execute(context, opts, *args) + def execute(context, opts, args) return if noop? || !available?(opts) block_arity = action_block.arity - return unless block_arity == -1 || block_arity == args.size + return unless (args.present? && block_arity == 1) || (args.blank? && block_arity <= 0) - context.instance_exec(*args, &action_block) + context.instance_exec(args, &action_block) end def to_h(opts) diff --git a/lib/gitlab/slash_commands/extractor.rb b/lib/gitlab/slash_commands/extractor.rb index 02c4c8c492e..c790b825347 100644 --- a/lib/gitlab/slash_commands/extractor.rb +++ b/lib/gitlab/slash_commands/extractor.rb @@ -50,15 +50,6 @@ module Gitlab end private - - def command_names(opts) - command_definitions.flat_map do |command| - next if command.noop? - - command.all_names - end.compact - end - # Builds a regular expression to match known commands. # First match group captures the command name and # second match group captures its arguments. @@ -117,6 +108,14 @@ module Gitlab ) }mx end + + def command_names(opts) + command_definitions.flat_map do |command| + next if command.noop? + + command.all_names + end.compact + end end end end |