lib/pgit/configuration.rb in pgit-0.0.4 vs lib/pgit/configuration.rb in pgit-1.0.0

- old
+ new

@@ -23,14 +23,38 @@ } ] } end + attr_reader :config_path, :yaml + def initialize(config_path = '~/.pgit.rc.yml') - @validator = PGit::Configuration::Validator.new(config_path) + @config_path = config_path + @expanded_path = File.expand_path(config_path) + @yaml = YAML::load_file(@expanded_path) || {} + @projs = @yaml.fetch("projects") { [] } + rescue Exception => e + if e.message.match(/No such file or directory/) + f = File.new(@expanded_path, 'w'); + f.close + end end - def to_yaml - @validator.yaml + def projects=(new_projects) + @projs = new_projects.map {|p| p.to_hash} + end + + def projects + @projs.map {|proj| PGit::Project.new(self, proj) } + end + + def to_hash + { 'projects' => projects.map { |proj| proj.to_hash } } + end + + def save! + file = File.new(@expanded_path, 'w') + YAML.dump(to_hash, file) + file.close end end end