lib/poe.rb in poe-0.0.0 vs lib/poe.rb in poe-0.0.2

- old
+ new

@@ -1,56 +1,114 @@ +require 'fileutils' + class Poe + + @@hooks = ['build-failed', 'build-worked', 'common.rb'] + + def initialize(dir) + @dir = dir + end + + def run + unless valid? + display_errors + return + end + setup + puts "drop kick => '#@dir'" + end + + def setup + #copy the hooks + copy_hooks + #setup the default runner + setup_runner + end + + + 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 + + def setup_runner + `cd #@dir && git config --add cijoe.runner "bundle exec rspec spec"` + end + + def home_dir + File.expand_path('~') + end + + 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 + + def errors + @errors ||= [] + end + + def display_errors + puts "Dang! something's wrong:\n\t#{errors.join("\n\t")}" + end + end