Class: Clustr::Config::Clusters

Inherits:
Hash
  • Object
show all
Defined in:
lib/clustr/config/clusters.rb

Overview

Handles determining the configuration for clusters that are present on the machine. Note that configurations should be defined in “~/.clustr”.

Class Method Summary collapse

Class Method Details

.configurationhash

Returns the configuration for the clusters that have been defined inside the “~/.clustr/” folder. Note that the filename for each configuration, becomes the determined name for that cluster.

Returns:

  • (hash)

    A hash of the clusters and their accompanying configuration (including the adapter and key).



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/clustr/config/clusters.rb', line 23

def self.configuration
  clusters ||= self.new

  config_files.each do |file|
    cluster = Pathname.new(file).basename.to_s
    clusters[cluster] = {}
    File.open(file, 'r') do |fh|
      fh.each_line do |line|
        key, val = line.strip.split(%r(\s*=\s*))
        clusters[cluster][key] = val if key && val
      end
    end
  end

  clusters
end

.configured?boolean

Determines if there are any configured clusters.

Returns:

  • (boolean)

    True if one or more configuration are present, false otherwise.



12
13
14
# File 'lib/clustr/config/clusters.rb', line 12

def self.configured?
  !configuration.empty?
end