Class: Dockit::Config
- Inherits:
-
Object
- Object
- Dockit::Config
- Defined in:
- lib/dockit/config.rb
Constant Summary collapse
- ENVFILE =
'.env'
Instance Method Summary collapse
-
#get(name, key = nil) ⇒ Object
- The
Dockit.yaml
file should have top-level entries for (at least)build
and/orcreate
name - Top-level key key
-
key in
name
hash ==== Returns - Hash forname
ifkey
is nil.
- The
-
#initialize(file, locals = {}) ⇒ Config
constructor
Instantiate and parse the file.
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
ifkey
is nil. -
Value of
key
inname
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 |