class Knife::Helper::Config

Attributes

commands[R]
option_sets[R]
settings[R]

Public Class Methods

new(file=nil) click to toggle source
# File lib/knife/helper/config.rb, line 11
def initialize(file=nil)
  file ||= default_file
  conf = load_config(file)
  @settings = conf['settings']
  @option_sets = conf['option_sets']
  @commands = conf['commands']
end

Public Instance Methods

default_file() click to toggle source
# File lib/knife/helper/config.rb, line 34
def default_file
  ::File.join(Dir.pwd, ".knife.helper.yml")
end
get_content(str) click to toggle source
# File lib/knife/helper/config.rb, line 42
def get_content(str)
  ::ERB.new(str).result
end
load_config(file) click to toggle source
# File lib/knife/helper/config.rb, line 19
def load_config(file)
  conf = load_yml(get_content(read_file(file)))
  Array(conf['includes']).each do |inc|
    inc_path = nil
    rel_path = File.expand_path("../#{inc}", file)
    [inc, rel_path].each {|f| inc_path = f if File.exists?(f) }
    raise "'#{inc}' is not exists." if inc_path.nil?
    conf = Chef::Mixin::DeepMerge.deep_merge(
      load_yml(get_content(read_file(inc_path))),
      conf
    )
  end
  conf
end
load_yml(str) click to toggle source
# File lib/knife/helper/config.rb, line 46
def load_yml(str)
  ::SafeYAML.load(str) || Hash.new
end
read_file(file) click to toggle source
# File lib/knife/helper/config.rb, line 38
def read_file(file)
  ::File.exist?(file.to_s) ? IO.read(file) : ""
end