Class: HammerCLI::Connection
- Inherits:
-
Object
- Object
- HammerCLI::Connection
- Defined in:
- lib/hammer_cli/connection.rb
Instance Method Summary collapse
- #available ⇒ Object
- #create(name, &create_connector_block) ⇒ Object
- #drop(name) ⇒ Object
- #drop_all ⇒ Object
- #exist?(name) ⇒ Boolean
- #get(name) ⇒ Object
-
#initialize(logger = nil) ⇒ Connection
constructor
A new instance of Connection.
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
#available ⇒ Object
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_all ⇒ Object
17 18 19 |
# File 'lib/hammer_cli/connection.rb', line 17 def drop_all() connections.keys.each { |c| drop(c) } end |
#exist?(name) ⇒ 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 |