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.
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, **) 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.
51 52 53 |
# File 'lib/synco/server.rb', line 51 def host @host end |
#mountpoint ⇒ Object
Returns the value of attribute mountpoint.
59 60 61 |
# File 'lib/synco/server.rb', line 59 def mountpoint @mountpoint end |
#name ⇒ Object (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 |
#root ⇒ Object
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 |
#shell ⇒ Object
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_command ⇒ Object
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.(directory.to_s, @root) Directory.normalize(path) end |
#same_host?(other) ⇒ Boolean
81 82 83 |
# File 'lib/synco/server.rb', line 81 def same_host?(other) @host == other.host end |
#to_s ⇒ Object
String representation of the server for logging.
86 87 88 |
# File 'lib/synco/server.rb', line 86 def to_s "#{@host}:#{full_path}" end |