Method: Falsework::Mould.config_parse

Defined in:
lib/falsework/mould.rb

.config_parse(file, rvars, hash) ⇒ Object

Parse a config. Return false on error.

file

A file to parse.

rvars

A list of variable names which must be in the config.

hash

a hash to merge results with



233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
# File 'lib/falsework/mould.rb', line 233

def self.config_parse(file, rvars, hash)
  r = true
  
  if File.readable?(file)
    begin
      myconf = YAML.load_file(file)
    rescue
      CliUtils.warnx "cannot parse #{file}: #{$!}"
      return false
    end
    rvars.each { |i|
      CliUtils.warnx "missing or nil '#{i}' in #{file}" if ! myconf.key?(i.to_sym) || ! myconf[i.to_sym]
      r = false
    }
    
    hash.merge!(myconf) if r && hash
  else
    r = false
  end
  
  r
end