Class: Poe

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

Constant Summary collapse

@@hooks =
['build-failed', 'build-worked', 'common.rb']

Instance Method Summary collapse

Constructor Details

#initialize(dir) ⇒ Poe

Returns a new instance of Poe.



7
8
9
# File 'lib/poe.rb', line 7

def initialize(dir)
  @dir = dir
end

Instance Method Details

#copy_hooksObject



28
29
30
31
32
33
34
35
36
# File 'lib/poe.rb', line 28

def copy_hooks
  src_dir = File.join(home_dir, '.poe', 'hooks')
  tgt_dir = File.join(@dir, '.git', 'hooks')

  @@hooks.each do |h|
    FileUtils.cp File.join(src_dir, h), tgt_dir
  end

end

#display_errorsObject



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

def display_errors
  puts "Dang! something's wrong:\n\t#{errors.join("\n\t")}"
end

#errorsObject



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

def errors
  @errors ||= []
end

#home_dirObject



42
43
44
# File 'lib/poe.rb', line 42

def home_dir
  File.expand_path('~')
end

#runObject



11
12
13
14
15
16
17
18
# File 'lib/poe.rb', line 11

def run
  unless valid?
    display_errors
    return
  end
  setup
  puts "drop kick => '#@dir'"
end

#setupObject



20
21
22
23
24
25
# File 'lib/poe.rb', line 20

def setup
  #copy the hooks
  copy_hooks
  #setup the default runner
  setup_runner
end

#setup_runnerObject



38
39
40
# File 'lib/poe.rb', line 38

def setup_runner
  `cd #@dir && git config --add cijoe.runner "bundle exec rspec spec"`
end

#valid?Boolean

Returns:

  • (Boolean)


46
47
48
49
50
# File 'lib/poe.rb', line 46

def valid?
  errors << "'#{@dir}' does not exist" unless File.exists?(@dir)
  errors << "'#{@dir}' is not a git repo" unless File.exists?(File.join(@dir, '.git'))
  errors.empty?
end