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.
-
#roles ⇒ Object
The roles that dictate how the server fits into the overall infratstructure.
-
#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
-
#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, options = {}) ⇒ Server
constructor
A new instance of Server.
-
#local? ⇒ Boolean
Checks if the host resolves to the local machine.
- #role?(role) ⇒ Boolean
-
#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
47 48 49 |
# File 'lib/lsync/server.rb', line 47 def host @host end |
#platform ⇒ Object
The platform of the server, e.g. linux, used for executing actions.
53 54 55 |
# File 'lib/lsync/server.rb', line 53 def platform @platform end |
#roles ⇒ Object
The roles that dictate how the server fits into the overall infratstructure.
44 45 46 |
# File 'lib/lsync/server.rb', line 44 def roles @roles end |
#root ⇒ Object
The root path on the server in which all other directories will be relative to.
50 51 52 |
# File 'lib/lsync/server.rb', line 50 def root @root end |
#shell ⇒ Object
The shell to use to connect to the server.
56 57 58 |
# File 'lib/lsync/server.rb', line 56 def shell @shell end |
Instance Method Details
#connection_string(directory) ⇒ Object
Give a general connection string (e.g “host:/directory” or “/directory” if local).
66 67 68 69 70 71 72 |
# File 'lib/lsync/server.rb', line 66 def connection_string(directory) if local? return full_path(directory) else return @host + ":" + full_path(directory).to_cmd end end |
#full_path(directory = "./") ⇒ Object
Give the full path for a particular subdirectory.
59 60 61 62 63 |
# File 'lib/lsync/server.rb', line 59 def full_path(directory = "./") p = File.(directory.to_s, @root) return Pathname.new(p).cleanpath.normalize_trailing_slash end |
#local? ⇒ Boolean
Checks if the host resolves to the local machine.
79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/lsync/server.rb', line 79 def local? return true if @host == "localhost" hostname = Socket.gethostname begin hostname = Socket.gethostbyname(hostname)[0] rescue SocketError puts $! end return @host == hostname end |
#role?(role) ⇒ Boolean
74 75 76 |
# File 'lib/lsync/server.rb', line 74 def role?(role) @roles.include?(role) || @roles.include?(:all) || role == :any end |
#to_s ⇒ Object
String representation of the server for logging.
94 95 96 |
# File 'lib/lsync/server.rb', line 94 def to_s "#{@host}:#{full_path}" end |