Class: Synco::Server

Inherits:
Controller show all
Defined in:
lib/synco/server.rb

Direct Known Subclasses

ServerScope

Instance Attribute Summary collapse

Attributes inherited from Controller

#events

Instance Method Summary collapse

Methods inherited from Controller

#abort!, build, #fire, #freeze, #on, #try

Constructor Details

#initialize(name, root: '/', shell: nil, **options) ⇒ Server

Returns a new instance of Server.



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/synco/server.rb', line 29

def initialize(name, root: '/', shell: nil, **options)
	super()
	
	@name = name
	
	case @name
	when Symbol
		@host = "localhost"
	else
		@host = name.to_s
	end
	
	@root = root
	@shell = shell || Shells::SSH.new
	
	@options = options
end

Instance Attribute Details

#hostObject

The host name (e.g. DNS entry) for the given server.



51
52
53
# File 'lib/synco/server.rb', line 51

def host
  @host
end

#mountpointObject

Returns the value of attribute mountpoint.



59
60
61
# File 'lib/synco/server.rb', line 59

def mountpoint
  @mountpoint
end

#nameObject (readonly)

The name of the server in the configuration (might be the same as the host).



48
49
50
# File 'lib/synco/server.rb', line 48

def name
  @name
end

#rootObject

The root path on the server in which all other directories will be relative to.



54
55
56
# File 'lib/synco/server.rb', line 54

def root
  @root
end

#shellObject

The shell to use to connect to the server.



57
58
59
# File 'lib/synco/server.rb', line 57

def shell
  @shell
end

Instance Method Details

#connection_commandObject



77
78
79
# File 'lib/synco/server.rb', line 77

def connection_command
	@shell.connection_command(self)
end

#connection_string(directory, on: nil) ⇒ Object

Give a general connection string (e.g “host:/directory” or “/directory” if local).



69
70
71
72
73
74
75
# File 'lib/synco/server.rb', line 69

def connection_string(directory, on: nil)
	if self.host == on.host
		return full_path(directory).to_s
	else
		return @host + ":" + Shellwords.escape(full_path(directory))
	end
end

#full_path(directory = "") ⇒ Object

Give the full path for a particular subdirectory.



62
63
64
65
66
# File 'lib/synco/server.rb', line 62

def full_path(directory = "")
	path = File.expand_path(directory.to_s, @root)
	
	Directory.normalize(path)
end

#same_host?(other) ⇒ Boolean

Returns:

  • (Boolean)


81
82
83
# File 'lib/synco/server.rb', line 81

def same_host?(other)
	@host == other.host
end

#to_sObject

String representation of the server for logging.



86
87
88
# File 'lib/synco/server.rb', line 86

def to_s
	"#{@host}:#{full_path}"
end