class Pencil::Models::Host

Attributes

cluster[R]
graphs[RW]

Public Class Methods

find(name) click to toggle source
# File lib/pencil/models/host.rb, line 29
def self.find(name)
  return @@objects[self.name][key] rescue []
end
find_by_cluster(cluster) click to toggle source
# File lib/pencil/models/host.rb, line 80
def self.find_by_cluster(cluster)
  ret = []
  Host.each do |name, host|
    ret << host if host.cluster == cluster
  end
  return ret
end
find_by_name_and_cluster(name, cluster) click to toggle source
# File lib/pencil/models/host.rb, line 72
def self.find_by_name_and_cluster(name, cluster)
  Host.each do |host_name, host|
    next unless host.name == name
    return host if host.cluster == cluster
  end
  return nil
end
new(name, cluster, params={}) click to toggle source
Calls superclass method Pencil::Models::Base::new
# File lib/pencil/models/host.rb, line 10
def initialize(name, cluster, params={})
  super(name, params)
  @cluster = cluster
  # hack for the case where colo{1,2}.host1 both exist
  @@objects[self.class.to_s].delete(name)
  @@objects[self.class.to_s]["#{cluster}#{name}"] = self

  @graphs = []
  Graph.each do |graph_name, graph|
    graph["hosts"].each do |h|
      if match(h)
        @graphs << graph
        break
      end
    end # graph["hosts"].each
  end # Graph.each
  @graphs.sort!
end

Public Instance Methods

<=>(other) click to toggle source
# File lib/pencil/models/host.rb, line 45
def <=>(other)
  if @params[:host_sort] == "builtin"
    return key <=> other.key
  elsif @params[:host_sort] == "numeric"
    regex = /\d+/
    match = @name.match(regex)
    match2 = other.name.match(regex)
    if match.pre_match != match2.pre_match
      return match.pre_match <=> match2.pre_match
    else
      return match[0].to_i <=> match2[0].to_i
    end
  else
    # http://www.bofh.org.uk/2007/12/16/comprehensible-sorting-in-ruby
    sensible = lambda do |k|
      k.to_s.split(
             /((?:(?:^|\s)[-+])?(?:\.\d+|\d+(?:\.\d+?(?:[eE]\d+)?(?:$|(?![eE\.])))?))/ms
             ).map { |v| Float(v) rescue v.downcase }
    end
    return sensible.call(self) <=> sensible.call(other)
  end
end
==(other) click to toggle source
# File lib/pencil/models/host.rb, line 41
def ==(other)
  key == other.key
end
eql?(other) click to toggle source
# File lib/pencil/models/host.rb, line 37
def eql?(other)
  key == other.key
end
hash() click to toggle source
# File lib/pencil/models/host.rb, line 68
def hash
  key.hash
end
key() click to toggle source
# File lib/pencil/models/host.rb, line 33
def key
  "#{@cluster}#{@name}"
end