Class: GitSemverCop::Generator

Inherits:
Thor
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/git-semver-cop/generator.rb

Overview

Our generator that creates the commit hook

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.destinationObject



12
13
14
15
16
17
18
19
20
21
# File 'lib/git-semver-cop/generator.rb', line 12

def self.destination
  # For submodules which have a .git file that points to the module
  hooks_dir = "/hooks/pre-commit"

  if File.file?(".git")
    File.expand_path(submodule_git + hooks_dir, Dir.pwd)
  else
    File.expand_path(".git" + hooks_dir, Dir.pwd)
  end
end

.source_rootObject



8
9
10
# File 'lib/git-semver-cop/generator.rb', line 8

def self.source_root
  File.expand_path("../../hooks", __FILE__)
end

.submodule_gitObject



23
24
25
# File 'lib/git-semver-cop/generator.rb', line 23

def self.submodule_git
  File.read(".git").strip[/^(gitdir: )(.+)$/, 2]
end

Instance Method Details

#destroyObject



34
35
36
# File 'lib/git-semver-cop/generator.rb', line 34

def destroy
  remove_file self.class.destination
end

#initObject



28
29
30
31
# File 'lib/git-semver-cop/generator.rb', line 28

def init
  copy_file "pre-commit", self.class.destination
  chmod self.class.destination, 0744
end