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.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/synco/server.rb', line 14

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.



36
37
38
# File 'lib/synco/server.rb', line 36

def host
  @host
end

#mountpointObject

Returns the value of attribute mountpoint.



44
45
46
# File 'lib/synco/server.rb', line 44

def mountpoint
  @mountpoint
end

#nameObject (readonly)

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



33
34
35
# File 'lib/synco/server.rb', line 33

def name
  @name
end

#rootObject

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



39
40
41
# File 'lib/synco/server.rb', line 39

def root
  @root
end

#shellObject

The shell to use to connect to the server.



42
43
44
# File 'lib/synco/server.rb', line 42

def shell
  @shell
end

Instance Method Details

#connection_commandObject



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

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).



54
55
56
57
58
59
60
# File 'lib/synco/server.rb', line 54

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.



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

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

#same_host?(other) ⇒ Boolean

Returns:

  • (Boolean)


66
67
68
# File 'lib/synco/server.rb', line 66

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

#to_sObject

String representation of the server for logging.



71
72
73
# File 'lib/synco/server.rb', line 71

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