Class: Dockit::Config

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

Constant Summary collapse

ENVFILE =
'.env'

Instance Method Summary collapse

Constructor Details

#initialize(file, locals = {}) ⇒ Config

Instantiate and parse the file.

file [String]

dockit yaml file

locals [Hash]

local variables to bind in the ERB context



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/dockit/config.rb', line 17

def initialize(file, locals={})
  root = Dockit::Env.new.root
  Dotenv.load(File.join(root, ENVFILE))
  locals['root'] ||= root

  begin
    @config = YAML::load(ERB.new(File.read(file)).result(bindings(locals)))
  rescue NameError => e
    error(e)
  rescue ArgumentError => e
    error(e)
  end
end

Instance Method Details

#get(name, key = nil) ⇒ Object

The Dockit.yaml file should have top-level entries for (at least) build and/or create

name

Top-level key

key

key in name hash

Returns

  • Hash for name if key is nil.

  • Value of key in name hash.



38
39
40
41
42
43
# File 'lib/dockit/config.rb', line 38

def get(name, key=nil)
  phase = @config[name.to_s]
  return phase unless key && phase

  phase[key.to_s]
end