Module: Orly::Installation

Defined in:
lib/orly/installation.rb

Constant Summary collapse

HOOK_PATH =
File.join ".git", "hooks", "post-merge"
HOOK_DIR =
File.join ".git", "hooks"
HOOK_CONTENT =
<<END
#!/bin/sh
orly --run
END

Class Method Summary collapse

Class Method Details

.installObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/orly/installation.rb', line 11

def self.install
    if not File.directory?(".git")
      puts "You don't appear to be in the base directory of a git project.".red
      exit 1
    end

    Dir.mkdir(HOOK_DIR) unless File.directory?(HOOK_DIR)

    if File.exists? HOOK_PATH
      puts "A post-merge hook already exists for this project.".red
      exit 1
    end

    File.open(HOOK_PATH, 'w') {|f| f.write(HOOK_CONTENT) }
    FileUtils.chmod 0755, HOOK_PATH
    puts "installed O RLY hook as:".green
    puts "  -> #{File.expand_path(HOOK_PATH)}".green
    puts "(to remove later, you can use: orly --uninstall)"
end

.uninstallObject



31
32
33
34
35
36
37
38
# File 'lib/orly/installation.rb', line 31

def self.uninstall
  if File.exists? HOOK_PATH
    FileUtils.rm HOOK_PATH
    puts "uninstalled #{HOOK_PATH}".green
  else
    puts "O RLY is not enabled for this directory, so there is nothing to uninstall.".yellow
  end
end