Class: TrackerGitHook::Repo

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root_path:) ⇒ Repo

Returns a new instance of Repo.



19
20
21
# File 'lib/tracker_git_hook/repo.rb', line 19

def initialize(root_path:)
  @root_path = root_path
end

Instance Attribute Details

#root_pathObject (readonly)

Returns the value of attribute root_path.



17
18
19
# File 'lib/tracker_git_hook/repo.rb', line 17

def root_path
  @root_path
end

Class Method Details

.discover(path:) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/tracker_git_hook/repo.rb', line 3

def self.discover(path:)
  git_directory = File.join(path, '.git')

  if File.exist?(git_directory)
    Repo.new(root_path: path)
  else
    parent_path = File.dirname(path)

    fail 'Not in a git repo' if parent_path == path

    discover(path: parent_path)
  end
end

Instance Method Details

#clear_story_idObject



37
38
39
# File 'lib/tracker_git_hook/repo.rb', line 37

def clear_story_id
  self.current_story_id = nil
end

#current_story_idObject



29
30
31
32
33
34
35
# File 'lib/tracker_git_hook/repo.rb', line 29

def current_story_id
  return unless File.exist?(story_file_path)

  story_id = File.read(story_file_path)

  story_id unless story_id.empty?
end

#current_story_id=(story_id) ⇒ Object



23
24
25
26
27
# File 'lib/tracker_git_hook/repo.rb', line 23

def current_story_id=(story_id)
  File.open(story_file_path, 'w') do |f|
    f.write(story_id)
  end
end

#install_hook(hook) ⇒ Object



41
42
43
44
45
46
47
48
# File 'lib/tracker_git_hook/repo.rb', line 41

def install_hook(hook)
  hook_path = File.join(root_path, '.git', 'hooks', hook.filename)

  File.open(hook_path, 'w') do |f|
    f.write(hook.script)
    f.chmod(0755)
  end
end