Sha256: 1946b421db720d1bee3ff1e641ad71edaf367f5af34ce87c1b95403e710a9e1a

Contents?: true

Size: 1.65 KB

Versions: 126

Compression:

Stored size: 1.65 KB

Contents

task :gem_installer do
  class GemInstaller
    def initialize(options = {}, &block)
      @gems = []
      @options = options

      run(&block)
    end

    def run(&block)
      instance_eval(&block) if block_given?
    end

    def gem(name, version = nil, options = {})
      if version.respond_to?(:merge!)
        options = version
      else
        options[:version] = version
      end

      @gems << [name, options]
    end

    def setup_gemspec(gemspec)
      gemspec.dependencies.each do |dependency|
        dependency.version_requirements.as_list.each do |version|
          gem(dependency.name, version)
        end
      end

      setup
    end

    def setup
      require 'rubygems'
      require 'rubygems/dependency_installer'

      @gems.each do |name, options|
        setup_gem(name, options)
      end
    end

    def setup_gem(name, options, try_install = true)
      print "activating #{name} ... "
      Gem.activate(name, *[options[:version]].compact)
      require(options[:lib] || name)
      puts "success."
    rescue LoadError => error
      puts error
      install_gem(name, options) if try_install
      setup_gem(name, options, try_install = false)
    end

    def install_gem(name, options)
      installer = Gem::DependencyInstaller.new(options)

      temp_argv(options[:extconf]) do
        print "Installing #{name} ... "
        installer.install(name, options[:version])
        puts "done."
      end
    end

    def temp_argv(extconf)
      if extconf ||= @options[:extconf]
        old_argv = ARGV.clone
        ARGV.replace(extconf.split(' '))
      end

      yield

    ensure
      ARGV.replace(old_argv) if extconf
    end
  end
end

Version data entries

126 entries across 118 versions & 25 rubygems

Version Path
Pistos-ramaze-2009.04.08 tasks/gem_installer.rake
bougyman-autumn-3.1.1 tasks/gem_installer.rake
bougyman-autumn-3.1.10 lib/skel/tasks/gem_installer.rake
bougyman-autumn-3.1.10 tasks/gem_installer.rake
bougyman-autumn-3.1.11 lib/skel/tasks/gem_installer.rake
bougyman-autumn-3.1.11 tasks/gem_installer.rake
bougyman-autumn-3.1.3 tasks/gem_installer.rake
bougyman-autumn-3.1.4 tasks/gem_installer.rake
bougyman-autumn-3.1.6 tasks/gem_installer.rake
bougyman-autumn-3.1.7 tasks/gem_installer.rake
bougyman-autumn-3.1.8 tasks/gem_installer.rake
bougyman-autumn-3.1.9 lib/skel/tasks/gem_installer.rake
bougyman-autumn-3.1.9 tasks/gem_installer.rake
bougyman-freeswitcher-0.1.4 tasks/gem_installer.rake
bougyman-freeswitcher-0.3.0 tasks/gem_installer.rake
bougyman-freeswitcher-0.3.1 tasks/gem_installer.rake
bougyman-freeswitcher-0.4.0 tasks/gem_installer.rake
bougyman-freeswitcher-0.4.1 tasks/gem_installer.rake
bougyman-freeswitcher-0.4.2 tasks/gem_installer.rake
bougyman-name_parse-0.0.3 tasks/gem_installer.rake