class Hatchet::Config
This class is responsible for parsing hatchet.json into something meaninful.
Constants
- REPOS_DIRECTORY_ROOT
- REPOS_DIR_NAME
Attributes
dirs[RW]
repos[RW]
Public Class Methods
new(directory = '.')
click to toggle source
creates new config object, pass in directory where ‘heroku.json` is located
# File lib/hatchet/config.rb, line 32 def initialize(directory = '.') self.repos = {} self.dirs = {} Dir.chdir(directory) do config_file = File.open('hatchet.json').read init_config! JSON.parse(config_file) end rescue Errno::ENOENT raise MissingConfig rescue JSON::ParserError => e raise ParserError, "Improperly formatted json in 'hatchet.json' \n\n" + e.message end
Public Instance Methods
name_from_git_repo(repo)
click to toggle source
‘git@github.com:codetriage/codetriage.git’ => ‘codetriage’
# File lib/hatchet/config.rb, line 56 def name_from_git_repo(repo) repo.split('/').last.chomp('.git') end
path_for_name(name)
click to toggle source
use this method to turn “codetriage” into repos/rails3/codetriage
# File lib/hatchet/config.rb, line 46 def path_for_name(name) possible_paths = [repos[name.to_s], "#{repo_directory_path}/#{name}", name].compact path = possible_paths.detect do |path| !(Dir[path] && Dir[path].empty?) end raise BadRepoName.new(name, possible_paths) if path.nil? || path.empty? path end
repo_directory_path()
click to toggle source
# File lib/hatchet/config.rb, line 26 def repo_directory_path File.join(@repo_directory_path, REPOS_DIR_NAME) end
Private Instance Methods
init_config!(config)
click to toggle source
pulls out config and makes easy to use hashes dirs has the repo paths as keys and the git_repos as values repos has repo names as keys and the paths as values
# File lib/hatchet/config.rb, line 71 def init_config!(config) set_internal_config!(config) config.each do |(directory, git_repos)| git_repos.each do |git_repo| git_repo = git_repo.include?("github.com") ? git_repo : "https://github.com/#{git_repo}.git" repo_name = name_from_git_repo(git_repo) repo_path = File.join(repo_directory_path, directory, repo_name) if repos.key? repo_name puts " warning duplicate repo found: #{repo_name.inspect}" repos[repo_name] = false else repos[repo_name] = repo_path end dirs[repo_path] = git_repo end end end
set_internal_config!(config)
click to toggle source
# File lib/hatchet/config.rb, line 62 def set_internal_config!(config) @internal_config = config.delete('hatchet') || {} @repo_directory_path = @internal_config['directory'] || REPOS_DIRECTORY_ROOT config end