Class: TBM::Target

Inherits:
Object
  • Object
show all
Defined in:
lib/TBM/target.rb

Overview

A target defines a tunnel or set of tunnels that can be created by invoking one or more names assigned to the target.

It has a name, a host, a user, and one or more tunnels well as an optional list of aliases.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, host, username) ⇒ Target



10
11
12
13
14
15
16
# File 'lib/TBM/target.rb', line 10

def initialize( name, host, username )
	@name = name
	@host = host
	@username = username
	@tunnels = []
	@aliases = []
end

Instance Attribute Details

#hostObject (readonly)

Returns the value of attribute host.



8
9
10
# File 'lib/TBM/target.rb', line 8

def host
  @host
end

#nameObject (readonly)

Returns the value of attribute name.



8
9
10
# File 'lib/TBM/target.rb', line 8

def name
  @name
end

#tunnelsObject (readonly)

Returns the value of attribute tunnels.



8
9
10
# File 'lib/TBM/target.rb', line 8

def tunnels
  @tunnels
end

#usernameObject (readonly)

Returns the value of attribute username.



8
9
10
# File 'lib/TBM/target.rb', line 8

def username
  @username
end

Instance Method Details

#add_alias(name) ⇒ Object

Adds an alias to the list of recognized aliases supported by the target.



28
29
30
# File 'lib/TBM/target.rb', line 28

def add_alias( name )
	@aliases << name
end

#add_tunnel(tunnel) ⇒ Object

Adds a tunnel to the target.



21
22
23
# File 'lib/TBM/target.rb', line 21

def add_tunnel( tunnel )
	@tunnels << tunnel
end

#each_tunnel(&block) ⇒ Object



36
37
38
# File 'lib/TBM/target.rb', line 36

def each_tunnel( &block )
	@tunnels.each { |tunnel| yield tunnel }
end

#has_name?(name) ⇒ Boolean



32
33
34
# File 'lib/TBM/target.rb', line 32

def has_name?( name )
	( @name == name ) || ( @aliases.include? name )
end

#has_tunnels?Boolean



48
49
50
# File 'lib/TBM/target.rb', line 48

def has_tunnels?
	!@tunnels.empty?
end

#to_sObject



40
41
42
43
44
45
46
# File 'lib/TBM/target.rb', line 40

def to_s
	if @aliases.empty?
		@name
	else
		"#{@name} (#{@aliases.join(', ')})"
	end
end