Module: Clamsy::Configuration

Included in:
BundledFileConfig, UserFileConfig, UserProcConfig
Defined in:
lib/clamsy/configuration.rb

Constant Summary collapse

ENV_REPLACE_PATTERN =
/(\$\{(.*?)\})/

Class Method Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object



41
42
43
44
# File 'lib/clamsy/configuration.rb', line 41

def method_missing(method, *args)
  !"#{method}".include?('=') ? get_config_var(method) :
    set_config_var("#{method}".sub('=','').to_sym, args[0])
end

Class Method Details

.merge_configs(*args) ⇒ Object



32
33
34
35
36
37
38
39
# File 'lib/clamsy/configuration.rb', line 32

def self.merge_configs(*args)
  args.inject({}) do |memo, hash|
    hash.inject(memo) do |m, arg|
      key, val = arg
      key == :config_src ? m.merge(key => val) : m.merge("#{key}" => val)
    end
  end
end

.new(file, is_base_config, default_config = {}) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/clamsy/configuration.rb', line 12

def self.new(file, is_base_config, default_config={})
  if (config = YAML.load_file(path = File.expand_path(file)) rescue nil)
    config = replace_with_env_vars(config)
    klass, config = is_base_config ? [BundledFileConfig, config[platform]] : [UserFileConfig, config]
    klass.new(default_config.merge(config).merge(:config_src => path))
  end
end

.platformObject



20
21
22
23
24
25
26
# File 'lib/clamsy/configuration.rb', line 20

def self.platform
  case ruby_platform
    when /linux/  then 'linux'
    when /darwin/ then 'darwin'
    else raise PlatformNotSupportedError.new("Platform '#{ruby_platform}' is not supported (yet).")
  end
end

.ruby_platformObject



28
29
30
# File 'lib/clamsy/configuration.rb', line 28

def self.ruby_platform
  RUBY_PLATFORM
end