Class: Liebre::ConnectionManager

Inherits:
Object
  • Object
show all
Defined in:
lib/liebre/connection_manager.rb

Instance Method Summary collapse

Constructor Details

#initialize(path = Liebre::Config.connection_path) ⇒ ConnectionManager

Returns a new instance of ConnectionManager.



7
8
9
10
# File 'lib/liebre/connection_manager.rb', line 7

def initialize path = Liebre::Config.connection_path
  @path = path
  @connections = {}
end

Instance Method Details

#ensure_startedObject



19
20
21
22
23
24
# File 'lib/liebre/connection_manager.rb', line 19

def ensure_started
  all_open = !@connections.empty? and @connections.all? do |_, bunny|
    bunny.open?
  end
  restart unless all_open
end

#get(connection_name) ⇒ Object



31
32
33
# File 'lib/liebre/connection_manager.rb', line 31

def get connection_name
  connections[connection_name.to_sym]
end

#restartObject



26
27
28
29
# File 'lib/liebre/connection_manager.rb', line 26

def restart
  stop
  start
end

#startObject



12
13
14
15
16
17
# File 'lib/liebre/connection_manager.rb', line 12

def start
  initialize_connections
  connections.each do |_, bunny|
    bunny.start
  end
end

#stopObject



35
36
37
38
39
40
41
42
# File 'lib/liebre/connection_manager.rb', line 35

def stop
  connections.each do |_, bunny|
    if bunny and bunny.open?
      bunny.close
    end
  end
  connections.clear
end