Class: Smith::Commands::Rm

Inherits:
Smith::CommandBase show all
Defined in:
lib/smith/commands/smithctl/rm.rb

Instance Attribute Summary

Attributes inherited from Smith::CommandBase

#options, #target

Instance Method Summary collapse

Methods inherited from Smith::CommandBase

#banner, #format_help, #initialize, #parse_options

Methods included from Logger

included

Constructor Details

This class inherits a constructor from Smith::CommandBase

Instance Method Details

#executeObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/smith/commands/smithctl/rm.rb', line 5

def execute
  case target.size
  when 0
    responder.succeed("No queue specified. Please specify a queue.")
  else
    @on_error = proc do |ch,channel_close|
      case channel_close.reply_code
      when 404
        responder.succeed("No such queue: [#{channel_close.reply_code}]: #{channel_close.reply_text}")
      when 406
        responder.succeed("Queue not empty: [#{channel_close.reply_code}]: #{channel_close.reply_text}.")
      else
        responder.succeed("Unknown error: [#{channel_close.reply_code}]: #{channel_close.reply_text}")
      end
    end

    target.each do |queue_name|
      delete_queue(queue_name) do |delete_ok|
        delete_exchange(queue_name) do |delete_ok|
          responder.succeed((options[:verbose]) ? delete_ok.message_count.to_s : nil)
        end
      end
    end
  end
end