Skip to content
This repository has been archived by the owner on Jun 8, 2019. It is now read-only.

Commit

Permalink
Remove duplicated code
Browse files Browse the repository at this point in the history
  • Loading branch information
tapajos committed Aug 29, 2011
1 parent 91989a1 commit 239b07b
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 60 deletions.
1 change: 1 addition & 0 deletions lib/kumade.rb
@@ -1,6 +1,7 @@
require 'rake'
require 'thor'

require 'kumade/base'
require 'kumade/git'
require 'kumade/deployer'
require 'kumade/runner'
Expand Down
30 changes: 30 additions & 0 deletions lib/kumade/base.rb
@@ -0,0 +1,30 @@
module Kumade
class Base < Thor::Shell::Color
def initialize
super()
end

def run_or_error(commands, error_message)
all_commands = [commands].flatten.join(' && ')
if @pretending
say_status(:run, all_commands)
else
error(error_message) unless run(all_commands)
end
end

def run(command, config = {})
say_status :run, command
config[:capture] ? `#{command}` : system("#{command}")
end

def error(message)
say("==> ! #{message}", :red)
exit 1
end

def success(message)
say("==> #{message}", :green)
end
end
end
25 changes: 1 addition & 24 deletions lib/kumade/deployer.rb
@@ -1,5 +1,5 @@
module Kumade
class Deployer < Thor::Shell::Color
class Deployer < Base
DEPLOY_BRANCH = "deploy"
attr_reader :environment, :pretending, :git

Expand Down Expand Up @@ -144,29 +144,6 @@ def custom_task?
Rake::Task.task_defined?("kumade:before_asset_compilation")
end

def run_or_error(commands, error_message)
all_commands = [commands].flatten.join(' && ')
if pretending
say_status(:run, all_commands)
else
error(error_message) unless run(all_commands)
end
end

def run(command, config = {})
say_status :run, command
config[:capture] ? `#{command}` : system("#{command}")
end

def error(message)
say("==> ! #{message}", :red)
exit 1
end

def success(message)
say("==> #{message}", :green)
end

def ensure_heroku_remote_exists
if git.remote_exists?(environment)
if app_name = Kumade.app_for(environment)
Expand Down
25 changes: 1 addition & 24 deletions lib/kumade/git.rb
@@ -1,5 +1,5 @@
module Kumade
class Git < Thor::Shell::Color
class Git < Base
def initialize(pretending, environment)
super()
@pretending = pretending
Expand Down Expand Up @@ -58,29 +58,6 @@ def ensure_clean_git
end
end

def run_or_error(commands, error_message)
all_commands = [commands].flatten.join(' && ')
if @pretending
say_status(:run, all_commands)
else
error(error_message) unless run(all_commands)
end
end

def run(command, config = {})
say_status :run, command
config[:capture] ? `#{command}` : system("#{command}")
end

def error(message)
say("==> ! #{message}", :red)
exit 1
end

def success(message)
say("==> #{message}", :green)
end

def branch_exist?(branch)
branches = `git branch`
regex = Regexp.new('[\\n\\s\\*]+' + Regexp.escape(branch.to_s) + '\\n')
Expand Down
13 changes: 13 additions & 0 deletions spec/kumade/base_spec.rb
@@ -0,0 +1,13 @@
require 'spec_helper'

describe Kumade::Base, "#success" do
it "exists" do
subject.should respond_to(:success)
end
end

describe Kumade::Base, "#error" do
it "exists" do
subject.should respond_to(:error)
end
end
12 changes: 0 additions & 12 deletions spec/kumade/deployer_spec.rb
Expand Up @@ -446,18 +446,6 @@ class More
end
end

describe Kumade::Deployer, "#success" do
it "exists" do
subject.should respond_to(:success)
end
end

describe Kumade::Deployer, "#error" do
it "exists" do
subject.should respond_to(:error)
end
end

describe Kumade::Deployer, "#post_deploy" do
before { subject.stub(:git => @git_mock = mock()) }

Expand Down

0 comments on commit 239b07b

Please sign in to comment.