Class: LSync::Server
- Inherits:
-
Object
- Object
- LSync::Server
- Includes:
- EventHandler
- Defined in:
- lib/lsync/server.rb
Instance Attribute Summary collapse
-
#host ⇒ Object
The host name (e.g. DNS entry) for the given server.
-
#platform ⇒ Object
The platform of the server, e.g.
-
#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.
Instance Method Summary collapse
-
#connect ⇒ Object
Connect to the server using the given #shell and #connection_string.
-
#connection_string(directory) ⇒ 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(host) ⇒ Server
constructor
A new instance of Server.
-
#is_local? ⇒ Boolean
Checks if the host resolves to the local machine.
-
#to_s ⇒ Object
String representation of the server for logging.
Methods included from EventHandler
Constructor Details
Instance Attribute Details
#host ⇒ Object
The host name (e.g. DNS entry) for the given server
23 24 25 |
# File 'lib/lsync/server.rb', line 23 def host @host end |
#platform ⇒ Object
The platform of the server, e.g. linux, used for executing actions.
29 30 31 |
# File 'lib/lsync/server.rb', line 29 def platform @platform end |
#root ⇒ Object
The root path on the server in which all other directories will be relative to.
26 27 28 |
# File 'lib/lsync/server.rb', line 26 def root @root end |
#shell ⇒ Object
The shell to use to connect to the server.
32 33 34 |
# File 'lib/lsync/server.rb', line 32 def shell @shell end |
Instance Method Details
#connect ⇒ Object
Connect to the server using the given #shell and #connection_string.
71 72 73 74 75 76 77 |
# File 'lib/lsync/server.rb', line 71 def connect unless @connection @connection, @pid = @shell.connect(self) end return @connection end |
#connection_string(directory) ⇒ Object
Give a general connection string (e.g “host:/directory” or “/directory” if local).
42 43 44 45 46 47 48 |
# File 'lib/lsync/server.rb', line 42 def connection_string(directory) if is_local? return full_path(directory) else return @host + ":" + full_path(directory).dump end end |
#full_path(directory = "./") ⇒ Object
Give the full path for a particular subdirectory.
35 36 37 38 39 |
# File 'lib/lsync/server.rb', line 35 def full_path(directory = "./") p = File.(directory.to_s, @root) return Pathname.new(p).cleanpath.normalize_trailing_slash.to_s end |
#is_local? ⇒ Boolean
Checks if the host resolves to the local machine.
51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/lsync/server.rb', line 51 def is_local? return true if @host == "localhost" hostname = Socket.gethostname begin hostname = Socket.gethostbyname(hostname)[0] rescue SocketError puts $! end return @host == hostname end |
#to_s ⇒ Object
String representation of the server for logging.
66 67 68 |
# File 'lib/lsync/server.rb', line 66 def to_s "#{@host}:#{full_path}" end |