Class: Liebre::Bridge

Inherits:
Object
  • Object
show all
Defined in:
lib/liebre/bridge.rb,
lib/liebre/bridge/channel_builder.rb

Defined Under Namespace

Classes: ChannelBuilder

Constant Summary collapse

NotStarted =
Class.new(StandardError)

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Bridge

Returns a new instance of Bridge.



9
10
11
12
# File 'lib/liebre/bridge.rb', line 9

def initialize config
  @config  = config
  @started = false
end

Instance Method Details

#open_channel(opts) ⇒ Object



29
30
31
32
33
34
35
36
# File 'lib/liebre/bridge.rb', line 29

def open_channel opts
  if started?
    builder = ChannelBuilder.new(connections, opts)
    builder.call
  else
    raise NotStarted
  end
end

#startObject



18
19
20
21
22
23
24
25
26
27
# File 'lib/liebre/bridge.rb', line 18

def start
  if not started?
    connections.each do |name, conn|
      conn.start
      logger.info("Connection started: #{name.inspect}")
    end

    self.started = true
  end
end

#started?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/liebre/bridge.rb', line 14

def started?
  @started
end

#stopObject



38
39
40
41
42
43
44
# File 'lib/liebre/bridge.rb', line 38

def stop
  if started?
    connections.each { |_name, conn| conn.stop }

    self.started = false
  end
end