Class: OodCore::Clusters
- Inherits:
-
Object
- Object
- OodCore::Clusters
- Includes:
- Enumerable
- Defined in:
- lib/ood_core/clusters.rb
Overview
An enumerable that contains a list of Cluster objects
Constant Summary collapse
- CONFIG_VERSION =
The format version of the configuration file
['v2', 'v1']
Class Method Summary collapse
-
.load_file(path) ⇒ Clusters
Parse a configuration file or a set of configuration files in a directory.
Instance Method Summary collapse
-
#[](id) ⇒ Cluster?
Find cluster in list using the id of the cluster.
-
#each {|cluster| ... } ⇒ Object
For a block {|cluster| …}.
-
#initialize(clusters = []) ⇒ Clusters
constructor
A new instance of Clusters.
Constructor Details
#initialize(clusters = []) ⇒ Clusters
97 98 99 |
# File 'lib/ood_core/clusters.rb', line 97 def initialize(clusters = []) @clusters = clusters end |
Class Method Details
.load_file(path) ⇒ Clusters
Parse a configuration file or a set of configuration files in a directory
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/ood_core/clusters.rb', line 17 def load_file(path) config = Pathname.new(path.to_s). clusters = [] if config.file? CONFIG_VERSION.any? do |version| YAML.safe_load(config.read).fetch(version, {}).each do |k, v| clusters << Cluster.new(send("parse_#{version}", id: k, cluster: v)) end !clusters.empty? end elsif config.directory? Pathname.glob(config.join("*.yml")).each do |p| CONFIG_VERSION.any? do |version| if cluster = YAML.safe_load(p.read).fetch(version, nil) clusters << Cluster.new(send("parse_#{version}", id: p.basename(".yml").to_s, cluster: cluster)) true else false end end end else raise ConfigurationNotFound, "configuration file '#{config}' does not exist" end new clusters end |
Instance Method Details
#[](id) ⇒ Cluster?
Find cluster in list using the id of the cluster
104 105 106 |
# File 'lib/ood_core/clusters.rb', line 104 def [](id) @clusters.detect { |cluster| cluster == id } end |
#each {|cluster| ... } ⇒ Object
For a block {|cluster| …}
110 111 112 |
# File 'lib/ood_core/clusters.rb', line 110 def each(&block) @clusters.each(&block) end |