Class: Synco::Server
- Inherits:
-
Controller
- Object
- Controller
- Synco::Server
- Defined in:
- lib/synco/server.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#host ⇒ Object
The host name (e.g. DNS entry) for the given server.
-
#mountpoint ⇒ Object
Returns the value of attribute mountpoint.
-
#name ⇒ Object
readonly
The name of the server in the configuration (might be the same as the host).
-
#root ⇒ Object
The root path on the server in which all other directories will be relative to.
-
#shell ⇒ Object
The shell to use to connect to the server.
Attributes inherited from Controller
Instance Method Summary collapse
- #connection_command ⇒ Object
-
#connection_string(directory, on: nil) ⇒ Object
Give a general connection string (e.g “host:/directory” or “/directory” if local).
-
#full_path(directory = "") ⇒ Object
Give the full path for a particular subdirectory.
-
#initialize(name, root: "/", shell: nil, **options) ⇒ Server
constructor
A new instance of Server.
- #same_host?(other) ⇒ Boolean
-
#to_s ⇒ Object
String representation of the server for logging.
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, **) super() @name = name case @name when Symbol @host = "localhost" else @host = name.to_s end @root = root @shell = shell || Shells::SSH.new @options = end |
Instance Attribute Details
#host ⇒ Object
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 |
#mountpoint ⇒ Object
Returns the value of attribute mountpoint.
44 45 46 |
# File 'lib/synco/server.rb', line 44 def mountpoint @mountpoint end |
#name ⇒ Object (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 |
#root ⇒ Object
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 |
#shell ⇒ Object
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_command ⇒ Object
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.(directory.to_s, @root) Directory.normalize(path) end |
#same_host?(other) ⇒ Boolean
66 67 68 |
# File 'lib/synco/server.rb', line 66 def same_host?(other) @host == other.host end |
#to_s ⇒ Object
String representation of the server for logging.
71 72 73 |
# File 'lib/synco/server.rb', line 71 def to_s "#{@host}:#{full_path}" end |