Module: Zillabyte::CLI::Config

Defined in:
lib/zillabyte/cli/config.rb

Constant Summary collapse

DEFAULT_CONFIG_FILE =
"zillabyte.conf.yaml"

Class Method Summary collapse

Class Method Details

.get_config_info(dir, session = nil, options = {}) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/zillabyte/cli/config.rb', line 11

def self.get_config_info(dir, session = nil, options = {})
 
  conf_file = nil
  if options[:config_file] and File.exists?(options[:config_file])
    conf_file = options[:config_file]
  else
    conf_file = File.join(dir, options[:config_file] || DEFAULT_CONFIG_FILE)
  end
  type = options[:output_type]

  return nil unless File.exists?(conf_file)
  require("yaml")
  hash = YAML.load_file(conf_file)
  
  # set other fields on the configuraiton
  hash['pwd'] = dir
  
  # The top_dir and rel_home_dir allows us to package up dependencies that
  # belong to sibling directories (e.g. the collectors directory)
  top_dir = File.expand_path(hash['top_dir'] || ".", dir)
  require("pathname")
  top_path = Pathname.new(top_dir)
  rel_dir = Pathname.new(dir).relative_path_from(top_path).to_s

  ignore_files = if hash.has_key?("ignore_files")
    ignore_files = hash["ignore_files"]
    ignore_files_array = ignore_files.respond_to?(:to_a) ? ignore_files.to_a() : [ignore_files]
    ignore_files_array.map { |path_arg|
      # It's annoying to fail because of an improperly specified path, though that would be my preference,
      # so we just warn.  It would be nice if APIDock covered what exceptions can be raised, too--we probably
      # don't want to catch all of them.
      begin
        path_string = path_arg.to_s()
        path = Pathname.new(File.expand_path(path_string))
        path.relative_path_from(top_path).to_s()
      rescue Exception => e
        session.error(e.message() + "\n" + e.backtrace.join("\n"), type) if session
        nil
      end
    }.compact()
  else
    []
  end
  hash["rel_dir"] = rel_dir
  hash['top_dir'] = top_dir
  hash["home_dir"] = dir
  hash["ignore_files"] = ignore_files
  
  # Get the config  
  return hash
  
end