Class: BunnyCleaner

Inherits:
Object
  • Object
show all
Defined in:
lib/gorg_service/rspec/bunny_cleaner.rb

Defined Under Namespace

Classes: Session

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args, &block) ⇒ BunnyCleaner

Returns a new instance of BunnyCleaner.



24
25
26
# File 'lib/gorg_service/rspec/bunny_cleaner.rb', line 24

def initialize(*args, &block)
  @target=Session.new(*args, &block)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



28
29
30
# File 'lib/gorg_service/rspec/bunny_cleaner.rb', line 28

def method_missing(method, *args, &block)
  @target.send(method, *args, &block)
end

Class Method Details

.cleanObject



51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/gorg_service/rspec/bunny_cleaner.rb', line 51

def clean
  connections=[]
  @registered_channels.each do |ch|
    c=ch.connection
    connections<<c
    c.start unless c.status == :open

    c.with_channel do |chan|
      ch.queues.keys.each{|q| c.queue_exists?(q)&&chan.queue_delete(q) }
      ch.exchanges.keys.each{|ex| c.exchange_exists?(ex)&&chan.exchange_delete(ex) }
    end
  end
  connections.uniq.each{|c|c.stop}
end

.cleaning(&block) ⇒ Object



41
42
43
44
45
46
47
48
# File 'lib/gorg_service/rspec/bunny_cleaner.rb', line 41

def cleaning(&block)
  begin
    init_cleaning
    block.call
  ensure
    clean
  end
end

.init_cleaningObject



66
67
68
# File 'lib/gorg_service/rspec/bunny_cleaner.rb', line 66

def init_cleaning
  registered_channels.clear
end

.method_missing(method, *args, &block) ⇒ Object



32
33
34
# File 'lib/gorg_service/rspec/bunny_cleaner.rb', line 32

def self.method_missing(method, *args, &block)
  Bunny.send(method, *args, &block)
end

.registered_channelsObject



37
38
39
# File 'lib/gorg_service/rspec/bunny_cleaner.rb', line 37

def registered_channels
  @registered_channels||=[]
end