public
Rubygem
Description: Sprinkle is a software provisioning tool you can use to build remote servers with. eg. to install a Rails or Merb stack on a brand new slice directly after its been created
Homepage: http://sprinkle.rubyforge.org/
Clone URL: git://github.com/crafterm/sprinkle.git
sprinkle / lib / sprinkle / installers / gem.rb
100644 62 lines (55 sloc) 1.85 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
module Sprinkle
  module Installers
    # = Ruby Gem Package Installer
    #
    # The gem package installer installs ruby gems.
    #
    # The installer has a single optional configuration: source.
    # By changing source you can specify a given ruby gems
    # repository from which to install.
    #
    # == Example Usage
    #
    # First, a simple installation of the magic_beans gem:
    #
    # package :magic_beans do
    # description "Beans beans they're good for your heart..."
    # gem 'magic_beans'
    # end
    #
    # Second, install magic_beans gem from github:
    #
    # package :magic_beans do
    # gem 'magic_beans_package' do
    # source 'http://gems.github.com'
    # end
    # end
    #
    # As you can see, setting options is as simple as creating a
    # block and calling the option as a method with the value as
    # its parameter.
    class Gem < Installer
      attr_accessor :gem #:nodoc:
 
      def initialize(parent, gem, options = {}, &block) #:nodoc:
        super parent, options, &block
        @gem = gem
      end
 
      def source(location = nil) #:nodoc:
        # package defines an installer called source so here we specify a method directly
        # rather than rely on the automatic options processing since packages' method missing
        # won't be run
        return @options[:source] unless location
        @options[:source] = location
      end
 
      protected
 
        # rubygems 0.9.5+ installs dependencies by default, and does platform selection
 
        def install_commands #:nodoc:
          cmd = "gem install #{gem}"
          cmd << " --version '#{version}'" if version
          cmd << " --source #{source}" if source
          cmd << " --install-dir #{repository}" if option?(:repository)
          cmd
        end
        
    end
  end
end