class OodCluster::Cluster
An object that describes a given cluster of nodes used by an HPC center
Public Class Methods
@param servers [Hash{#to_sym=>Server}] hash of servers @param hpc_cluster [Boolean] whether this is an hpc cluster
# File lib/ood_cluster/cluster.rb, line 11 def initialize(servers: {}, hpc_cluster: true, **_) @servers = servers.each_with_object({}) { |(k, v), h| h[k.to_sym] = v } @hpc_cluster = hpc_cluster end
Public Instance Methods
The comparison operator @param other [#to_h] object to compare against @return [Boolean] whether objects are equivalent
# File lib/ood_cluster/cluster.rb, line 55 def ==(other) to_h == other.to_h end
Check whether objects are identical to each other @param other [#to_h] object to compare against @return [Boolean] whether objects are identical
# File lib/ood_cluster/cluster.rb, line 62 def eql?(other) self.class == other.class && self == other end
Generate a hash value for this object @return [Fixnum] hash value of object
# File lib/ood_cluster/cluster.rb, line 68 def hash [self.class, to_h].hash end
Whether this is an hpc-style cluster (i.e., meant for heavy computation) @return [Boolean] whether this an hpc-style cluster
# File lib/ood_cluster/cluster.rb, line 27 def hpc_cluster? @hpc_cluster end
Grab object from {@servers} hash or check if it exists @param method_name the method name called @param arguments the arguments to the call @param block an optional block for the call
# File lib/ood_cluster/cluster.rb, line 35 def method_missing(method_name, *arguments, &block) if /^(.+)_server$/ =~ method_name.to_s @servers.fetch($1.to_sym, nil) elsif /^(.+)_server\?$/ =~ method_name.to_s @servers.has_key?($1.to_sym) else super end end
Check if method ends with custom *_server or *_server? @param method_name the method name to check @return [Boolean]
# File lib/ood_cluster/cluster.rb, line 48 def respond_to_missing?(method_name, include_private = false) method_name.to_s.end_with?('_server', '_server?') || super end
Convert object to hash @return [Hash] the hash describing this object
# File lib/ood_cluster/cluster.rb, line 18 def to_h { servers: @servers, hpc_cluster: @hpc_cluster } end