class Dockit::Config

Constants

ENVFILE

Public Class Methods

new(file, locals={}) click to toggle source

Instantiate and parse the file.

file [String]

dockit yaml file

locals [Hash]

local variables to bind in the ERB context

# 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

Public Instance Methods

get(name, key=nil) click to toggle source

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.

# 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

Private Instance Methods

bindings(locals) click to toggle source

Generate bindings object for locals to pass to erb

locals

hash converted to local variables

Returns

binding object

# File lib/dockit/config.rb, line 49
def bindings(locals)
  b  = binding
  locals.each do |k,v|
    b.local_variable_set(k, v)
  end

  return b
end
error(e) click to toggle source
# File lib/dockit/config.rb, line 58
def error(e)
  abort [e.message.capitalize,
         "Did you forget '--locals key:value'?"].join("\n")
end