Skip to content

Commit

Permalink
Merge pull request sprinkle-tool#34 from selectport/master
Browse files Browse the repository at this point in the history
Added support for thor tasks installer (just like rake) ...
  • Loading branch information
crafterm committed Sep 9, 2011
2 parents cdc8295 + b9eefc6 commit 55c7078
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 0 deletions.
37 changes: 37 additions & 0 deletions lib/sprinkle/installers/thor.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
module Sprinkle
module Installers
# = Thor Installer
#
# This installer runs a thor command.
#
# == Example Usage
#
# The following example runs the command "thor spec" on
# the remote server.
#
# package :spec do
# thor 'spec'
# end
#
# Specify a Thorfile with the :thorfile option.
#
# package :spec, :thorfile => "/var/setup/Thorfile" do
# thor 'spec'
# end

class Thor < Installer
def initialize(parent, commands, options = {}, &block) #:nodoc:
super parent, options, &block
@commands = commands
end

protected

def install_commands #:nodoc:
file = @options[:thorfile] ? "-f #{@options[:thorfile]} " : ""
"thor #{file}#{@commands}"
end

end
end
end
4 changes: 4 additions & 0 deletions lib/sprinkle/package.rb
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,10 @@ def rake(name, options = {}, &block)
@installers << Sprinkle::Installers::Rake.new(self, name, options, &block)
end
def thor(name, options = {}, &block)
@installers << Sprinkle::Installers::Thor.new(self, name, options, &block)
end
def noop(&block)
@installers << Sprinkle::Installers::Noop.new(self, name, options, &block)
end
Expand Down
29 changes: 29 additions & 0 deletions spec/sprinkle/installers/thor_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
require File.expand_path("../../spec_helper", File.dirname(__FILE__))

describe Sprinkle::Installers::Thor do

before do
@package = mock(Sprinkle::Package, :name => 'spec')
end

def create_thor(names, options = {}, &block)
Sprinkle::Installers::Thor.new(@package, names, options, &block)
end

describe 'during installation' do

it 'should invoke the thor executer for all specified tasks' do
@installer = create_thor 'spec'
@install_commands = @installer.send :install_commands
@install_commands.should =~ /thor spec/
end

it 'should invoke the thor executer for all specified tasks' do
@installer = create_thor 'spec', :thorfile => '/some/Thorfile'
@install_commands = @installer.send :install_commands
@install_commands.should == "thor -f /some/Thorfile spec"
end

end

end

0 comments on commit 55c7078

Please sign in to comment.