class Chake::Node

Attributes

max_node_name_length[W]
data[R]
hostname[R]
port[R]
remote_username[R]
silent[RW]
username[R]

Public Class Methods

max_node_name_length() click to toggle source
# File lib/chake/node.rb, line 16
def self.max_node_name_length
  @max_node_name_length ||= 0
end
new(hostname, data = {}) click to toggle source
# File lib/chake/node.rb, line 24
def initialize(hostname, data = {})
  uri = parse_uri(hostname)
  @connection_name = uri.scheme
  @hostname = uri.host
  @port = uri.port
  @username = uri.user || Etc.getpwuid.name
  @remote_username = uri.user
  @path = uri.path
  @data = data
  set_max_node_length
end

Public Instance Methods

config_manager() click to toggle source
# File lib/chake/node.rb, line 42
def config_manager
  @config_manager ||= Chake::ConfigManager.get(self)
end
connection() click to toggle source
# File lib/chake/node.rb, line 36
def connection
  @connection ||= Chake::Connection.get(@connection_name).new(self)
end
log(msg) click to toggle source
# File lib/chake/node.rb, line 52
def log(msg)
  return if silent

  puts("%#{Node.max_node_name_length}<host>s: %<msg>s\n" % { host: hostname, msg: msg })
end
path() click to toggle source
# File lib/chake/node.rb, line 48
def path
  @path ||= config_manager.path
end

Private Instance Methods

incomplete_uri(uri) click to toggle source
# File lib/chake/node.rb, line 69
def incomplete_uri(uri)
  !uri.host && ((!uri.scheme && uri.path) || (uri.scheme && uri.opaque))
end
parse_uri(hostname) click to toggle source
# File lib/chake/node.rb, line 60
def parse_uri(hostname)
  uri = URI.parse(hostname)
  if incomplete_uri(uri)
    uri = URI.parse("ssh://#{hostname}")
  end
  uri.path = nil if uri.path.empty?
  uri
end
set_max_node_length() click to toggle source
# File lib/chake/node.rb, line 73
def set_max_node_length
  return if @hostname.length <= self.class.max_node_name_length

  self.class.max_node_name_length = @hostname.length
end