class Cangallo::Config

Constants

CONFIG_DIR
CONFIG_FILE
DEFAULT_CONFIG

Public Class Methods

new() click to toggle source
# File lib/cangallo/config.rb, line 34
def initialize
  create_config_dir
  create_default_config
  load_conf
end

Public Instance Methods

config_dir() click to toggle source
# File lib/cangallo/config.rb, line 83
def config_dir
  File.join(ENV['HOME'], CONFIG_DIR)
end
config_file() click to toggle source
# File lib/cangallo/config.rb, line 87
def config_file
  File.join(config_dir, CONFIG_FILE)
end
create_config_dir() click to toggle source
# File lib/cangallo/config.rb, line 59
def create_config_dir
  if !File.exist?(config_dir)
    FileUtils.mkdir_p(config_dir)
  end
end
create_default_config() click to toggle source
# File lib/cangallo/config.rb, line 65
def create_default_config
  if !File.exist?(config_file)
    open(config_file, 'w') do |f|
      f.write(DEFAULT_CONFIG)
    end

    load_conf
    path = File.expand_path(@conf["repos"]["default"]["path"])
    create_repo_dir(path)
  end
end
create_repo_dir(path) click to toggle source
# File lib/cangallo/config.rb, line 77
def create_repo_dir(path)
  if !File.exist?(path)
    FileUtils.mkdir_p(path)
  end
end
load_conf() click to toggle source
# File lib/cangallo/config.rb, line 55
def load_conf
  @conf = YAML.load_file(config_file)
end
repo(name = nil) click to toggle source
# File lib/cangallo/config.rb, line 40
def repo(name = nil)
  repo_name = name || @conf['default_repo'] || 'default'
  raise(%q{Configuration malformed, no 'repos'}) if !@conf['repos']

  repo_conf = @conf['repos'][repo_name]
  raise(%Q<No repo with name '#{repo_name}'>) if !repo_conf
  raise(%Q<Repo path no defined for '#{repo_name}'>) if !repo_conf['path']

  path = File.expand_path(repo_conf["path"])
  repo_conf["path"] = path
  repo_conf["name"] = repo_name
  create_repo_dir(path)
  Cangallo::Repo.new(repo_conf)
end
repos() click to toggle source
# File lib/cangallo/config.rb, line 91
def repos
  @conf["repos"].keys
end