class AssistedWorkflow::ConfigFile

class providing methods to load, manage and save configuration files

Public Class Methods

new(awfile) click to toggle source
# File lib/assisted_workflow/config_file.rb, line 51
def initialize(awfile)
  @awfile = awfile
  @hash = if File.exists?(@awfile)
    ConfigHash.new(::YAML::load_file(@awfile) || {})
  else
    ConfigHash.new
  end
end

Public Instance Methods

[](key) click to toggle source
# File lib/assisted_workflow/config_file.rb, line 36
def [](key)
  @hash[key]
end
merge_file(file) click to toggle source

merges other config file into the current one

# File lib/assisted_workflow/config_file.rb, line 45
def merge_file(file)
  other_config = ConfigFile.new(file)
  @hash.deep_merge!(other_config.to_hash)
  self
end
parse(args) click to toggle source

parse a command line arguments into configuration keys Example:

pivotal.token=mypivotaltoken
=> {:pivotal => {:token => "mypivotaltoken"}}
# File lib/assisted_workflow/config_file.rb, line 18
def parse(args)
  Array(args).each do |values|
    keys, value = values.split("=")
    keys.split(".").reverse.each do |k|
      value = {k => value}
    end
    @hash.deep_merge!(value)
  end
  self
end
save!() click to toggle source

dumps the configuration values to a file in yaml format

# File lib/assisted_workflow/config_file.rb, line 30
def save!
  content = @hash.to_yaml
  content.gsub! " !ruby/hash:AssistedWorkflow::ConfigHash", ""
  File.open(@awfile, 'w'){ |f| f.write(content) }
end
to_hash() click to toggle source
# File lib/assisted_workflow/config_file.rb, line 40
def to_hash
  @hash.dup
end