lib/pgit/configuration.rb in pgit-0.0.3 vs lib/pgit/configuration.rb in pgit-0.0.4
- old
+ new
@@ -24,54 +24,13 @@
]
}
end
def initialize(config_path = '~/.pgit.rc.yml')
- @expanded_path = File.expand_path(config_path)
- if File.exists? @expanded_path
- config_file = File.open(@expanded_path, 'r')
- @yaml = YAML.load(config_file)
-
- validate_existence_of_at_least_one_project
- validate_presence_of_items_in_each_project
- else
- raise missing_config_default
- end
+ @validator = PGit::Configuration::Validator.new(config_path)
end
def to_yaml
- @yaml
- end
-
- private
-
- def missing_config_default
- "Default configuration file does not exist. Please run `pgit install`"
- end
-
- def general_error_message
- "Please have the following layout:\n" + YAML.dump(PGit::Configuration.default_options)
- end
-
- def validate_presence_of_items_in_each_project
- projects = @yaml["projects"]
- all_present = projects.all? do |project|
- project["api_token"] &&
- project["path"] &&
- project["id"]
- end
-
- unless all_present
- raise "Error: Must have a path, id, and api_token for each project.\n" +
- general_error_message
- end
- end
-
- def validate_existence_of_at_least_one_project
- unless @yaml["projects"]
- raise "Error: #{@expanded_path} needs at least one project.\n" +
- general_error_message
-
- end
+ @validator.yaml
end
end
end