Class: Hatchet::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/hatchet/config.rb

Overview

This class is responsible for parsing hatchet.json into something meaninful.

Constant Summary collapse

REPOS_DIR_NAME =

the top level name of repos folder

"repos"
REPOS_DIRECTORY_ROOT =

the the root directory where your repos folder will be stored

'.'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(directory = '.') ⇒ Config

creates new config object, pass in directory where ‘heroku.json` is located



32
33
34
35
36
37
38
39
40
41
42
43
# 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

Instance Attribute Details

#dirsObject

Returns the value of attribute dirs.



24
25
26
# File 'lib/hatchet/config.rb', line 24

def dirs
  @dirs
end

#reposObject

Returns the value of attribute repos.



24
25
26
# File 'lib/hatchet/config.rb', line 24

def repos
  @repos
end

Instance Method Details

#name_from_git_repo(repo) ⇒ Object

[email protected]:codetriage/codetriage.git’ => ‘codetriage’



56
57
58
# File 'lib/hatchet/config.rb', line 56

def name_from_git_repo(repo)
  repo.split('/').last.chomp('.git')
end

#path_for_name(name) ⇒ Object

use this method to turn “codetriage” into repos/rails3/codetriage

Raises:



46
47
48
49
50
51
52
53
# 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_pathObject



26
27
28
# File 'lib/hatchet/config.rb', line 26

def repo_directory_path
  File.join(@repo_directory_path, REPOS_DIR_NAME)
end