Class: SSHClient::ConfigItem
- Inherits:
-
Object
- Object
- SSHClient::ConfigItem
- Defined in:
- lib/ssh_client/config_item.rb
Constant Summary collapse
- DEFAULT_NAME =
:default
- READ_TIMEOUT =
0.5
Instance Attribute Summary collapse
-
#debug ⇒ Object
writeonly
Sets the attribute debug.
-
#hostname ⇒ Object
Returns the value of attribute hostname.
- #logger ⇒ Object
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#password ⇒ Object
Returns the value of attribute password.
- #read_timeout ⇒ Object
- #transport ⇒ Object
-
#username ⇒ Object
Returns the value of attribute username.
Instance Method Summary collapse
- #add_listener(*args, &blk) ⇒ Object
- #debug? ⇒ Boolean
- #default? ⇒ Boolean
-
#initialize(name = nil) ⇒ ConfigItem
constructor
A new instance of ConfigItem.
- #listeners ⇒ Object
- #raise_on_errors=(value) ⇒ Object
- #remove_listener(listener, io_type = nil) ⇒ Object
- #transport_klass ⇒ Object
Constructor Details
#initialize(name = nil) ⇒ ConfigItem
Returns a new instance of ConfigItem.
12 13 14 15 16 17 |
# File 'lib/ssh_client/config_item.rb', line 12 def initialize(name = nil) @name = name || DEFAULT_NAME @listeners = { stdout: Set.new, stderr: Set.new } add_listener { |data| logger.info "<< #{data}" } if default? end |
Instance Attribute Details
#debug=(value) ⇒ Object (writeonly)
Sets the attribute debug
10 11 12 |
# File 'lib/ssh_client/config_item.rb', line 10 def debug=(value) @debug = value end |
#hostname ⇒ Object
Returns the value of attribute hostname.
8 9 10 |
# File 'lib/ssh_client/config_item.rb', line 8 def hostname @hostname end |
#logger ⇒ Object
64 65 66 |
# File 'lib/ssh_client/config_item.rb', line 64 def logger @logger || (default? ? Logger.new(STDOUT) : SSHClient.config.logger) end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
9 10 11 |
# File 'lib/ssh_client/config_item.rb', line 9 def name @name end |
#password ⇒ Object
Returns the value of attribute password.
8 9 10 |
# File 'lib/ssh_client/config_item.rb', line 8 def password @password end |
#read_timeout ⇒ Object
42 43 44 |
# File 'lib/ssh_client/config_item.rb', line 42 def read_timeout @read_timeout || (default? ? READ_TIMEOUT : SSHClient.config.read_timeout) end |
#transport ⇒ Object
46 47 48 |
# File 'lib/ssh_client/config_item.rb', line 46 def transport transport_klass.new self end |
#username ⇒ Object
Returns the value of attribute username.
8 9 10 |
# File 'lib/ssh_client/config_item.rb', line 8 def username @username end |
Instance Method Details
#add_listener(*args, &blk) ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/ssh_client/config_item.rb', line 27 def add_listener(*args, &blk) Array(args || @listeners.keys).each do |k| @listeners[k] << blk end @cached_listeners = nil blk end |
#debug? ⇒ Boolean
68 69 70 |
# File 'lib/ssh_client/config_item.rb', line 68 def debug? @debug || (default? ? false : SSHClient.config.debug?) end |
#default? ⇒ Boolean
72 73 74 |
# File 'lib/ssh_client/config_item.rb', line 72 def default? name == DEFAULT_NAME end |
#listeners ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/ssh_client/config_item.rb', line 19 def listeners @cached_listeners ||= if default? @listeners else @listeners.each { |k, l| l += SSHClient.config.listeners[k] } end end |
#raise_on_errors=(value) ⇒ Object
54 55 56 57 58 59 60 61 62 |
# File 'lib/ssh_client/config_item.rb', line 54 def raise_on_errors=(value) if value @errors_listener = add_listener(:stderr) do |data| Thread.main.raise CommandExitWithError.new(data) if data end else remove_listener(@errors_listener, :stderr) if @errors_listener end end |
#remove_listener(listener, io_type = nil) ⇒ Object
35 36 37 38 39 40 |
# File 'lib/ssh_client/config_item.rb', line 35 def remove_listener(listener, io_type = nil) Array(io_type || @listeners.keys).each do |k| @listeners[k].delete listener end @cached_listeners = nil end |