Class: Arcanus::Repo
- Inherits:
-
Object
- Object
- Arcanus::Repo
- Defined in:
- lib/arcanus/repo.rb
Overview
Exposes information about the current git repository.
Instance Method Summary collapse
- #arcanus_dir ⇒ Object
- #chest_file_path ⇒ Object
-
#git_dir ⇒ String
Returns an absolute path to the .git directory for a repo.
- #gitignore_file_path ⇒ Object
- #has_chest_file? ⇒ Boolean
- #has_locked_key? ⇒ Boolean
- #has_unlocked_key? ⇒ Boolean
-
#initialize(config) ⇒ Repo
constructor
A new instance of Repo.
- #locked_key_path ⇒ Object
-
#root ⇒ String
Returns the absolute path to the root of the current repository the current working directory resides within.
- #unlocked_key_path ⇒ Object
Constructor Details
#initialize(config) ⇒ Repo
Returns a new instance of Repo.
7 8 9 |
# File 'lib/arcanus/repo.rb', line 7 def initialize(config) @config = config end |
Instance Method Details
#arcanus_dir ⇒ Object
56 57 58 |
# File 'lib/arcanus/repo.rb', line 56 def arcanus_dir File.join(root, '.arcanus') end |
#chest_file_path ⇒ Object
64 65 66 |
# File 'lib/arcanus/repo.rb', line 64 def chest_file_path File.join(root, CHEST_FILE_PATH) end |
#git_dir ⇒ String
Returns an absolute path to the .git directory for a repo.
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.('.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.(git_dir, repo_dir) end end git_dir end end |
#gitignore_file_path ⇒ Object
60 61 62 |
# File 'lib/arcanus/repo.rb', line 60 def gitignore_file_path File.join(arcanus_dir, '.gitignore') end |
#has_chest_file? ⇒ 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
76 77 78 |
# File 'lib/arcanus/repo.rb', line 76 def has_locked_key? File.exist?(locked_key_path) end |
#has_unlocked_key? ⇒ Boolean
84 85 86 |
# File 'lib/arcanus/repo.rb', line 84 def has_unlocked_key? File.exist?(unlocked_key_path) end |
#locked_key_path ⇒ Object
72 73 74 |
# File 'lib/arcanus/repo.rb', line 72 def locked_key_path File.join(root, LOCKED_KEY_PATH) end |
#root ⇒ String
Returns the absolute path to the root of the current repository the current working directory resides within.
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.('.')) .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_path ⇒ Object
80 81 82 |
# File 'lib/arcanus/repo.rb', line 80 def unlocked_key_path File.join(root, UNLOCKED_KEY_PATH) end |