Class: Pipely::Build::EnvironmentConfig

Inherits:
Hash
  • Object
show all
Defined in:
lib/pipely/build/environment_config.rb

Overview

Work with YAML config files that contain parallel configs for various environments.

Constant Summary collapse

ENV_DEFAULTS =

Continue supporting env-based defaults until pipely v1.0

{
  production: {
    s3_prefix: 'production/:namespace',
    scheduler: 'daily',
    start_time: '11:00:00',
  },
  staging: {
    s3_prefix: 'staging/:whoami/:namespace',
    scheduler: 'now',

    # Since scheduler can now be overridden via commandline argument,
    # supply a start_time even for environments that default to 'now'.
    start_time: '11:00:00',
  }
}

Class Method Summary collapse

Class Method Details

.load(filename, environment) ⇒ Object



28
29
30
31
32
33
34
35
36
37
# File 'lib/pipely/build/environment_config.rb', line 28

def self.load(filename, environment)
  raw = YAML.load_file(filename)[environment.to_s]
  config = load_from_hash(raw)

  if defaults = ENV_DEFAULTS[environment.to_sym]
    defaults.merge(config)
  else
    config
  end
end

.load_from_hash(attributes) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/pipely/build/environment_config.rb', line 39

def self.load_from_hash(attributes)
  config = new

  attributes.each do |k, v|
    case v
    when Hash
      config[k.to_sym] = load_from_hash(v)
    else
      config[k.to_sym] = v.clone
    end
  end

  config
end