Skip to content

Commit

Permalink
added support for thor installer
Browse files Browse the repository at this point in the history
copied the rake installer and modified to do thor installer …
  • Loading branch information
selectport committed Sep 9, 2011
1 parent cdc8295 commit b9eefc6
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
@@ -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
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
@@ -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 b9eefc6

Please sign in to comment.