Class: SvnAuto::ConfigFile
- Inherits:
-
Object
- Object
- SvnAuto::ConfigFile
- 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
-
#[](name) ⇒ Object
helper methods.
- #[]=(name, value) ⇒ Object
-
#find_repository(name) ⇒ Object
locate a repository by it’s name.
-
#initialize ⇒ ConfigFile
constructor
load in the user’s configuration file.
-
#prompt_for_repository ⇒ Object
prompt the user to choose a repository.
-
#save ⇒ Object
save the configuration file.
Constructor Details
#initialize ⇒ ConfigFile
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_repository ⇒ Object
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 || .header = "Repositories" .prompt = "Please choose a repository: " @config[:repositories].each do |rep| .choice(rep.to_s) {rep} end end end |
#save ⇒ Object
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 |