class Dotman::Check::Host

Public Class Methods

new(aliases, hosts, include: true) click to toggle source
# File lib/dotman/checks/host.rb, line 3
    def initialize(aliases, hosts, include: true)
        @aliases, @hosts, @include = aliases, hosts, include
    end

    def to_comparison
        Shell.condition(hosts.map { |host| compare(host) }, condition_operator)
    end

    private

    def condition_operator
        if @include then :or else :and end
    end

    def comparison_operator
        if @include then '=' else '!=' end
    end

    def compare(host)
        Shell.comparison('$HOST', comparison_operator, host)
    end

    def hosts
        @hosts.map { |host| get_alias(host) }
    end

    def get_alias(target)
        @aliases[target] || target
    end
end

Public Instance Methods

compare(host) click to toggle source
# File lib/dotman/checks/host.rb, line 21
def compare(host)
    Shell.comparison('$HOST', comparison_operator, host)
end
comparison_operator() click to toggle source
# File lib/dotman/checks/host.rb, line 17
def comparison_operator
    if @include then '=' else '!=' end
end
condition_operator() click to toggle source
# File lib/dotman/checks/host.rb, line 13
def condition_operator
    if @include then :or else :and end
end
get_alias(target) click to toggle source
# File lib/dotman/checks/host.rb, line 29
def get_alias(target)
    @aliases[target] || target
end
hosts() click to toggle source
# File lib/dotman/checks/host.rb, line 25
def hosts
    @hosts.map { |host| get_alias(host) }
end
to_comparison() click to toggle source
# File lib/dotman/checks/host.rb, line 7
def to_comparison
    Shell.condition(hosts.map { |host| compare(host) }, condition_operator)
end