Class: CommitPhoto

Inherits:
Object
  • Object
show all
Defined in:
lib/commitphotos.rb,
lib/commitphotos/version.rb

Direct Known Subclasses

Image, Video

Constant Summary collapse

VERSION =
"0.0.4"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.imageObject



14
15
16
17
# File 'lib/commitphotos.rb', line 14

def self.image
  puts "Say cheese! Taking a photo."
  Image.new
end

.videoObject



19
20
21
22
# File 'lib/commitphotos.rb', line 19

def self.video
  puts "Say cheese! Taking a video."
  Video.new
end

Instance Method Details

#setup_hook(global, video) ⇒ Object

This will setup Commitphotos for the user.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/commitphotos.rb', line 25

def setup_hook(global, video)

  if global
    destination = File.expand_path(`git config --get init.templatedir`.chomp)
    create_global_hook_dir if destination.empty?
  else
    # We shouldn't require the user to be in a git repo if they're installing globally.
    abort 'Error: not a git repository.' unless File.exist? File.join(Dir.pwd, '.git')
    destination = File.expand_path(File.join(Dir.pwd, '.git/hooks'))
  end

  type = video ? :video : :image

  local_post_commit = "#{File.expand_path(File.dirname(__FILE__))}/commitphotos/hooks/post-commit-#{type}"

  FileUtils.mkdir_p(destination)
  content = hook_content(type)
  File.open(File.join(destination, 'post-commit'), 'w') { |file| file.write(content) }
  puts "You're good to go!"
end