Class: SvnAuto::ConfigFile

Inherits:
Object
  • Object
show all
Defined in:
lib/svnauto/config_file.rb

Constant Summary collapse

ENV_OVERRIDE =
'SvnAuto_CONFIG_FILE'
FILENAME =
File.join(ENV['HOME'], '.sva')

Instance Method Summary collapse

Constructor Details

#initializeConfigFile

load in the user’s configuration file



36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/svnauto/config_file.rb', line 36

def initialize
  @file_name = ENV[ENV_OVERRIDE] ? ENV[ENV_OVERRIDE] : FILENAME

  @config = 
    if File.exists?(@file_name)
      File.open(@file_name) {|file| YAML.load(file)}
    end

  @config = Hash.new unless @config.is_a?(Hash)
  @config[:repositories] ||= Array.new
  @config[:color] = false unless @config.has_key?(:color)
end

Instance Method Details

#[](name) ⇒ Object

helper methods



81
# File 'lib/svnauto/config_file.rb', line 81

def []  (name) @config[name] end

#[]=(name, value) ⇒ Object



82
# File 'lib/svnauto/config_file.rb', line 82

def []= (name, value) @config[name] = value end

#find_repository(name) ⇒ Object

locate a repository by it’s name



51
52
53
# File 'lib/svnauto/config_file.rb', line 51

def find_repository (name)
  @config[:repositories].find {|r| r.name == name}
end

#prompt_for_repositoryObject

prompt the user to choose a repository



57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/svnauto/config_file.rb', line 57

def prompt_for_repository
  if @config[:repositories].empty?
    raise "you don't have any repositories defined, use 'config --add'"
  end

  Constants::TERMINAL.choose do |menu|
    menu.header = "Repositories"
    menu.prompt = "Please choose a repository: "

    @config[:repositories].each do |rep|
      menu.choice(rep.to_s) {rep}
    end
  end
end

#saveObject

save the configuration file



73
74
75
76
77
# File 'lib/svnauto/config_file.rb', line 73

def save
  File.open(@file_name, "w") do |file|
    YAML.dump(@config, file)
  end
end