Class: Liebre::ConnectionManager
- Inherits:
-
Object
- Object
- Liebre::ConnectionManager
- Defined in:
- lib/liebre/connection_manager.rb
Instance Method Summary collapse
- #ensure_started ⇒ Object
- #get(connection_name) ⇒ Object
-
#initialize(path = Liebre::Config.connection_path) ⇒ ConnectionManager
constructor
A new instance of ConnectionManager.
- #restart ⇒ Object
- #start ⇒ Object
- #stop ⇒ Object
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_started ⇒ Object
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 |
#restart ⇒ Object
26 27 28 29 |
# File 'lib/liebre/connection_manager.rb', line 26 def restart stop start end |
#start ⇒ Object
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 |
#stop ⇒ Object
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 |