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
bougyman-name_parse-0.0.4 tasks/gem_installer.rake
bougyman-name_parse-0.0.5 tasks/gem_installer.rake
deathsyn-seedling-0.0.1 tasks/gem_installer.rake
deathsyn-seedling-0.0.1 lib/templates/core/tasks/gem_installer.rake
deathsyn-seedling-0.0.5 lib/templates/core/tasks/gem_installer.rake
manveru-innate-2009.04.01 tasks/gem_installer.rake
manveru-innate-2009.04.08 tasks/gem_installer.rake
manveru-innate-2009.04.18 tasks/gem_installer.rake
manveru-innate-2009.04 tasks/gem_installer.rake
manveru-innate-2009.05 tasks/gem_installer.rake
manveru-mailit-2009.08 tasks/gem_installer.rake
manveru-makura-2009.03.28 tasks/gem_installer.rake
manveru-makura-2009.04.22 tasks/gem_installer.rake
manveru-makura-2009.05.27 tasks/gem_installer.rake
manveru-nagoro-2009.03.28 tasks/gem_installer.rake
manveru-nagoro-2009.05 tasks/gem_installer.rake
manveru-org-2009.03.28 tasks/gem_installer.rake
manveru-ramaze-2009.04.01 tasks/gem_installer.rake
manveru-ramaze-2009.04.08 tasks/gem_installer.rake
manveru-ramaze-2009.04.18 tasks/gem_installer.rake