Class: ClusterManagement::Config

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

Class Method Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args) ⇒ Object (protected)



34
35
36
37
38
39
40
# File 'lib/cluster_management/config.rb', line 34

def method_missing m, *args
  if m =~ /=$/
    self[m[0..-2].to_sym] = args.first
  else
    self[m]
  end
end

Class Method Details

.attr_required(*attrs) ⇒ Object



26
27
28
29
30
# File 'lib/cluster_management/config.rb', line 26

def self.attr_required *attrs
  attrs.each do |m|
    define_method(m){self[m] || raise("key :#{m} not defined!")}
  end
end

Instance Method Details

#load_config!(runtime_path) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/cluster_management/config.rb', line 2

def load_config! runtime_path    
  merge! runtime_path: runtime_path, config_path: "#{runtime_path}/config"
  
  path = "#{runtime_path}/config/config.yml"
  raise("config file must have .yml extension (#{path})!") unless path.end_with? '.yml'

  data = ::YAML.load_file path
  if data
    data.must_be.a ::Hash
    data.each{|k, v| self[k.to_sym] = v}
  end

  # converting :handy_scheme to :scheme
  if include? :handy_scheme
    raise "You can't use both :handy_scheme and :scheme!" if include?(:scheme)
    self.scheme = {}
    handy_scheme.each do |box, tags|
      tags.each do |tag|
        (self.scheme[tag.to_sym] ||= []) << box
      end
    end
  end
end