Class: SentiaGitHooks::Cli
- Inherits:
-
Thor
- Object
- Thor
- SentiaGitHooks::Cli
- Defined in:
- lib/sentia_git_hooks/cli.rb
Instance Method Summary collapse
-
#initialize(*args) ⇒ Cli
constructor
A new instance of Cli.
- #install ⇒ Object
- #update ⇒ Object
Constructor Details
#initialize(*args) ⇒ Cli
Returns a new instance of Cli.
8 9 10 11 12 13 14 15 |
# File 'lib/sentia_git_hooks/cli.rb', line 8 def initialize(*args) super @scripts_dir = Pathname.new File.("../../scripts", __FILE__) @sentia_dir = Pathname.new("~/.sentia/"). @sentia_hooks_dir = @sentia_dir + "git-hooks" @new_hooks_dir = Pathname.new(Dir.pwd) + ".git/hooks" end |
Instance Method Details
#install ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/sentia_git_hooks/cli.rb', line 29 def install script_files = Dir.entries @sentia_hooks_dir script_files.delete(".") script_files.delete("..") script_files.each do |file| existing_script = @sentia_hooks_dir + file new_hook = File. file, @new_hooks_dir begin FileUtils.ln_s existing_script, new_hook exit 0 rescue puts "Failed If a hook file already exists then we refuse to clobber it, you'll have to delete it manually, or have it call the functionality in our hook." exit 1 end end end |
#update ⇒ Object
20 21 22 23 24 |
# File 'lib/sentia_git_hooks/cli.rb', line 20 def update FileUtils.mkdir_p @sentia_dir FileUtils.rm_f @sentia_hooks_dir FileUtils.ln_s @scripts_dir, @sentia_hooks_dir, force: true end |