Class: HammerCLI::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/hammer_cli/connection.rb

Instance Method Summary collapse

Constructor Details

#initialize(logger = nil) ⇒ Connection

Returns a new instance of Connection.



9
10
11
# File 'lib/hammer_cli/connection.rb', line 9

def initialize(logger = nil)
  @logger = logger
end

Instance Method Details

#availableObject



38
39
40
# File 'lib/hammer_cli/connection.rb', line 38

def available
  connections.select { |k, v| !v.nil? }.values.first
end

#create(name, &create_connector_block) ⇒ Object



21
22
23
24
25
26
27
28
# File 'lib/hammer_cli/connection.rb', line 21

def create(name, &create_connector_block)
  unless connections[name]
    connector = yield
    @logger.debug("Registered: #{name}") if @logger
    connections[name] = connector
  end
  connections[name]
end

#drop(name) ⇒ Object



13
14
15
# File 'lib/hammer_cli/connection.rb', line 13

def drop(name)
  connections.delete(name)
end

#drop_allObject



17
18
19
# File 'lib/hammer_cli/connection.rb', line 17

def drop_all()
  connections.keys.each { |c| drop(c) }
end

#exist?(name) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/hammer_cli/connection.rb', line 30

def exist?(name)
  !get(name).nil?
end

#get(name) ⇒ Object



34
35
36
# File 'lib/hammer_cli/connection.rb', line 34

def get(name)
  connections[name]
end