Class: OodCluster::Cluster
- Inherits:
-
Object
- Object
- OodCluster::Cluster
- Includes:
- JsonSerializer
- Defined in:
- lib/ood_cluster/cluster.rb
Overview
An object that describes a given cluster of nodes used by an HPC center
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
The comparison operator.
-
#eql?(other) ⇒ Boolean
Check whether objects are identical to each other.
-
#hash ⇒ Fixnum
Generate a hash value for this object.
-
#hpc_cluster? ⇒ Boolean
Whether this is an hpc-style cluster (i.e., meant for heavy computation).
-
#initialize(servers: {}, hpc_cluster: true, **_) ⇒ Cluster
constructor
A new instance of Cluster.
-
#method_missing(method_name, *arguments, &block) ⇒ Object
Grab object from @servers hash or check if it exists.
-
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
Check if method ends with custom *_server or *_server?.
-
#to_h ⇒ Hash
Convert object to hash.
Methods included from JsonSerializer
Constructor Details
#initialize(servers: {}, hpc_cluster: true, **_) ⇒ Cluster
Returns a new instance of Cluster.
11 12 13 14 |
# 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 |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *arguments, &block) ⇒ Object
Grab object from @servers hash or check if it exists
35 36 37 38 39 40 41 42 43 |
# 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 |
Instance Method Details
#==(other) ⇒ Boolean
The comparison operator
55 56 57 |
# File 'lib/ood_cluster/cluster.rb', line 55 def ==(other) to_h == other.to_h end |
#eql?(other) ⇒ Boolean
Check whether objects are identical to each other
62 63 64 |
# File 'lib/ood_cluster/cluster.rb', line 62 def eql?(other) self.class == other.class && self == other end |
#hash ⇒ Fixnum
Generate a hash value for this object
68 69 70 |
# File 'lib/ood_cluster/cluster.rb', line 68 def hash [self.class, to_h].hash end |
#hpc_cluster? ⇒ Boolean
Whether this is an hpc-style cluster (i.e., meant for heavy computation)
27 28 29 |
# File 'lib/ood_cluster/cluster.rb', line 27 def hpc_cluster? @hpc_cluster end |
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
Check if method ends with custom *_server or *_server?
48 49 50 |
# 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 |
#to_h ⇒ Hash
Convert object to hash
18 19 20 21 22 23 |
# File 'lib/ood_cluster/cluster.rb', line 18 def to_h { servers: @servers, hpc_cluster: @hpc_cluster } end |