Class: GitNotify

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

Class Method Summary collapse

Class Method Details

.applied_hook?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/gitnotify.rb', line 56

def self.applied_hook?
  File.read(post_commit).include?('growlnotify')
end

.disable_notifyObject



28
29
30
31
# File 'lib/gitnotify.rb', line 28

def self.disable_notify
  FileUtils.chmod 0664, post_commit
  puts "Gitnotify: Disabled post-commit"
end

.enable_notifyObject



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/gitnotify.rb', line 16

def self.enable_notify
  exit_with! "You're not within a git repository" unless git_repo?
  FileUtils.touch post_commit
  FileUtils.chmod 0775, post_commit
  unless applied_hook?
    File.open(post_commit, "w+") do |f|
      f << File.read(post_commit_script)
    end
  end
  puts "Gitnotify: Enabled post-commit"
end

.exit_with!(message) ⇒ Object



73
74
75
76
# File 'lib/gitnotify.rb', line 73

def self.exit_with!(message)
  STDERR.puts message
  exit!
end

.git_repo?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/gitnotify.rb', line 52

def self.git_repo?
  File.exists?(repo_path)
end

.helpObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/gitnotify.rb', line 33

def self.help
 puts "\n=========================\nGitnotify, railscamp love\n=========================\n\nTell your peeps about your commits using growl\n     \nUsage: (from within a git repo): gitnotify <command>\n       \nenable-hook\n Enables a post-commit hook\n    \ndisable-hook\n  Disables a post-commit hook\n"
end

.post_commitObject



65
66
67
# File 'lib/gitnotify.rb', line 65

def self.post_commit
  File.join(repo_path, "hooks", "post-commit")
end

.post_commit_scriptObject



69
70
71
# File 'lib/gitnotify.rb', line 69

def self.post_commit_script
  File.join(File.dirname(__FILE__), "..", "supports", "post-commit")
end

.repo_pathObject

Just a standard helper



61
62
63
# File 'lib/gitnotify.rb', line 61

def self.repo_path
  File.join(Dir.pwd, ".git")
end

.run(*args) ⇒ Object



4
5
6
7
8
9
10
11
12
13
# File 'lib/gitnotify.rb', line 4

def self.run(*args)
  case args.shift
  when "enable-hook"
    enable_notify
  when "disable-hook"
    disable_notify
  else
    help
  end
end