Sha256: c4e9060aadb104fd38db1c8a77e1bf15a21c0335e87a4b70b32b2c27d505a374

Contents?: true

Size: 1.95 KB

Versions: 26

Compression:

Stored size: 1.95 KB

Contents

# Copyright (C) 2012  Kouhei Sutou <kou@cozmixng.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

require "rabbit/gettext"

module Rabbit
  class GemFinder
    include GetText

    def initialize(logger=nil)
      @logger = logger || Logger.default
    end

    def find(name, prefix)
      normalized_name = name.downcase
      unless normalized_name.start_with?(prefix)
        normalized_name = "#{prefix}#{normalized_name}"
      end

      retried = false
      spec = nil
      begin
        spec = Gem::Specification.find_by_name(name)
      rescue Gem::LoadError
        begin
          spec = Gem::Specification.find_by_name(normalized_name)
        rescue Gem::LoadError
          unless retried
            retried = true
            require "rubygems/dependency_installer"
            options = {}
            if File.writable?(Gem.dir)
              @logger.info(_("Installing gem: %s") % normalized_name)
            else
              options[:user_install] = true
              format = _("Installing gem in user install mode: %s")
              @logger.info(format % normalized_name)
            end
            installer = Gem::DependencyInstaller.new(options)
            installer.install(normalized_name, Gem::Requirement.default)
            retry
          end
        end
      end
      spec
    end
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
rabbit-3.0.3 lib/rabbit/gem-finder.rb
rabbit-3.0.2 lib/rabbit/gem-finder.rb
rabbit-3.0.1 lib/rabbit/gem-finder.rb
rabbit-3.0.0 lib/rabbit/gem-finder.rb
rabbit-2.2.1 lib/rabbit/gem-finder.rb
rabbit-2.2.0 lib/rabbit/gem-finder.rb
rabbit-2.1.9 lib/rabbit/gem-finder.rb
rabbit-2.1.8 lib/rabbit/gem-finder.rb
rabbit-2.1.7 lib/rabbit/gem-finder.rb
rabbit-2.1.6 lib/rabbit/gem-finder.rb
rabbit-2.1.5 lib/rabbit/gem-finder.rb
rabbit-2.1.4 lib/rabbit/gem-finder.rb
rabbit-2.1.3 lib/rabbit/gem-finder.rb
rabbit-2.1.2 lib/rabbit/gem-finder.rb
rabbit-2.1.1 lib/rabbit/gem-finder.rb
rabbit-2.1.0 lib/rabbit/gem-finder.rb
rabbit-2.0.9 lib/rabbit/gem-finder.rb
rabbit-2.0.8 lib/rabbit/gem-finder.rb
rabbit-2.0.7 lib/rabbit/gem-finder.rb
rabbit-2.0.6 lib/rabbit/gem-finder.rb