install_gem (GemManagement)

    # File lib/merb-core/tasks/gem_management.rb, line 46
      def install_gem(gem, options = {})
        refresh = options.delete(:refresh) || []
        from_cache = (options.key?(:cache) && options.delete(:cache))
        if from_cache
          install_gem_from_cache(gem, options)
        else
          version = options.delete(:version)
          Gem.configuration.update_sources = false

          # Limit source index to install dir
          update_source_index(options[:install_dir]) if options[:install_dir]

          installer = Gem::DependencyInstaller.new(options.merge(:user_install => false))

          # Force-refresh certain gems by excluding them from the current index
          if !options[:ignore_dependencies] && refresh.respond_to?(:include?) && !refresh.empty?
            source_index = installer.instance_variable_get(:@source_index)
            source_index.gems.each do |name, spec|
              source_index.gems.delete(name) if refresh.include?(spec.name)
            end
          end

          exception = nil
          begin
            installer.install gem, version
          rescue Gem::InstallError => e
            exception = e
          rescue Gem::GemNotFoundException => e
            if from_cache && gem_file = find_gem_in_cache(gem, version)
              puts "Located #{gem} in gem cache..."
              installer.install gem_file
            else
              exception = e
            end
          rescue => e
            exception = e
          end
          if installer.installed_gems.empty? && exception
            error "Failed to install gem '#{gem} (#{version || 'any version'})' (#{exception.message})"
          end
          ensure_bin_wrapper_for_installed_gems(installer.installed_gems, options)
          installer.installed_gems.each do |spec|
            success "Successfully installed #{spec.full_name}"
          end
          return !installer.installed_gems.empty?
        end
      end