Class: Arcanus::Repo

Inherits:
Object
  • Object
show all
Defined in:
lib/arcanus/repo.rb

Overview

Exposes information about the current git repository.

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Repo

Returns a new instance of Repo.

Parameters:



7
8
9
# File 'lib/arcanus/repo.rb', line 7

def initialize(config)
  @config = config
end

Instance Method Details

#arcanus_dirObject



56
57
58
# File 'lib/arcanus/repo.rb', line 56

def arcanus_dir
  File.join(root, '.arcanus')
end

#chest_file_pathObject



64
65
66
# File 'lib/arcanus/repo.rb', line 64

def chest_file_path
  File.join(root, CHEST_FILE_PATH)
end

#git_dirString

Returns an absolute path to the .git directory for a repo.

Returns:

  • (String)


37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/arcanus/repo.rb', line 37

def git_dir
  @git_dir ||=
    begin
      git_dir = File.expand_path('.git', root)

      # .git could also be a file that contains the location of the git directory
      unless File.directory?(git_dir)
        git_dir = File.read(git_dir)[/^gitdir: (.*)$/, 1]

        # Resolve relative paths
        unless git_dir.start_with?('/')
          git_dir = File.expand_path(git_dir, repo_dir)
        end
      end

      git_dir
    end
end

#gitignore_file_pathObject



60
61
62
# File 'lib/arcanus/repo.rb', line 60

def gitignore_file_path
  File.join(arcanus_dir, '.gitignore')
end

#has_chest_file?Boolean

Returns:

  • (Boolean)


68
69
70
# File 'lib/arcanus/repo.rb', line 68

def has_chest_file?
  File.exist?(chest_file_path)
end

#has_locked_key?Boolean

Returns:

  • (Boolean)


76
77
78
# File 'lib/arcanus/repo.rb', line 76

def has_locked_key?
  File.exist?(locked_key_path)
end

#has_unlocked_key?Boolean

Returns:

  • (Boolean)


84
85
86
# File 'lib/arcanus/repo.rb', line 84

def has_unlocked_key?
  File.exist?(unlocked_key_path)
end

#locked_key_pathObject



72
73
74
# File 'lib/arcanus/repo.rb', line 72

def locked_key_path
  File.join(root, LOCKED_KEY_PATH)
end

#rootString

Returns the absolute path to the root of the current repository the current working directory resides within.

Returns:

  • (String)

Raises:



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/arcanus/repo.rb', line 17

def root
  @root ||=
    begin
      git_dir = Pathname.new(File.expand_path('.'))
                        .enum_for(:ascend)
                        .find do |path|
        (path + '.git').exist?
      end

      unless git_dir
        raise Errors::InvalidGitRepoError, 'no .git directory found'
      end

      git_dir.to_s
    end
end

#unlocked_key_pathObject



80
81
82
# File 'lib/arcanus/repo.rb', line 80

def unlocked_key_path
  File.join(root, UNLOCKED_KEY_PATH)
end