class LSync::Server

Attributes

host[RW]

The host name (e.g. DNS entry) for the given server

platform[RW]

The platform of the server, e.g. linux, used for executing actions.

roles[RW]

The roles that dictate how the server fits into the overall infratstructure.

root[RW]

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

shell[RW]

The shell to use to connect to the server.

Public Class Methods

new(host, options = {}) click to toggle source
# File lib/lsync/server.rb, line 28
def initialize(host, options = {})
        @options = options
 
        @host = host
        @root = "/"

        @platform = nil

        @shell = Shells::SSH.new

        @enabled = true

        @roles = Set.new
end

Public Instance Methods

connection_string(directory) click to toggle source

Give a general connection string (e.g +“host:/directory”+ or +“/directory”+ if local).

# 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 = "./") click to toggle source

Give the full path for a particular subdirectory.

# File lib/lsync/server.rb, line 59
def full_path(directory = "./")
        p = File.expand_path(directory.to_s, @root)

        return Pathname.new(p).cleanpath.normalize_trailing_slash
end
local?() click to toggle source

Checks if the host resolves to the local machine.

# 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) click to toggle source
# File lib/lsync/server.rb, line 74
def role?(role)
        @roles.include?(role) || @roles.include?(:all) || role == :any
end
to_s() click to toggle source

String representation of the server for logging.

# File lib/lsync/server.rb, line 94
def to_s
        "#{@host}:#{full_path}"
end