Class: RobotArmy::GateKeeper

Inherits:
Object
  • Object
show all
Defined in:
lib/robot-army/gate_keeper.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connection_class = RobotArmy::OfficerConnection) ⇒ GateKeeper

Returns a new instance of GateKeeper.



4
5
6
# File 'lib/robot-army/gate_keeper.rb', line 4

def initialize(connection_class=RobotArmy::OfficerConnection)
  @connection_class = connection_class
end

Instance Attribute Details

#connection_classObject (readonly)

Returns the value of attribute connection_class.



2
3
4
# File 'lib/robot-army/gate_keeper.rb', line 2

def connection_class
  @connection_class
end

Class Method Details

.shared_instanceObject



25
26
27
# File 'lib/robot-army/gate_keeper.rb', line 25

def self.shared_instance
  @shared_instance ||= new
end

Instance Method Details

#closeObject



21
22
23
# File 'lib/robot-army/gate_keeper.rb', line 21

def close
  connections.each { |host,c| c.close unless c.closed? }
end

#connect(host) ⇒ Object



8
9
10
# File 'lib/robot-army/gate_keeper.rb', line 8

def connect(host)
  connections[host] ||= establish_connection(host)
end

#connectionsObject



17
18
19
# File 'lib/robot-army/gate_keeper.rb', line 17

def connections
  @connections ||= {}
end

#establish_connection(host) ⇒ Object



12
13
14
15
# File 'lib/robot-army/gate_keeper.rb', line 12

def establish_connection(host)
  connection = connections[host] = connection_class.new(host)
  connection.open
end