123456789_123456789_123456789_123456789_123456789_

Class: Gem::Source::Local

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
Instance Chain:
self, ::Gem::Source, ::Gem::Text, Comparable
Inherits: Gem::Source
Defined in: lib/rubygems/source/local.rb

Overview

The local source finds gems in the current directory for fulfilling dependencies.

Constant Summary

::Gem::Source - Inherited

FILES

Class Method Summary

::Gem::Source - Inherited

.new

Creates a new ::Gem::Source which will use the index located at #uri.

Instance Attribute Summary

::Gem::Source - Inherited

#update_cache?

Returns true when it is possible and safe to update the cache directory.

#uri

The URI this source will fetch gems from.

Instance Method Summary

::Gem::Source - Inherited

#<=>

Sources are ordered by installation preference.

#cache_dir

Returns the local directory to write #uri to.

#download

Downloads spec and writes it to Gem.dir.

#fetch_spec

Fetches a specification for the given name_tuple.

#load_specs

Loads type kind of specs fetching from @uri if the on-disk cache is out of date.

#typo_squatting?, #enforce_trailing_slash, #==,
#dependency_resolver_set

Returns a Set that can fetch specifications from this source.

#eql?

Alias for #==.

#hash, #pretty_print

::Gem::Text - Included

#clean_text

Remove any non-printable characters and make the text suitable for printing.

#format_text

Wraps text to wrap characters and optionally indents by indent characters.

#levenshtein_distance

This code is based directly on the ::Gem::Text gem implementation Returns a value representing the “cost” of transforming str1 into str2.

#truncate_text, #min3

Constructor Details

.newLocal

This method is for internal use only.
[ GitHub ]

  
# File 'lib/rubygems/source/local.rb', line 7

def initialize # :nodoc:
  @specs   = nil
  @api_uri = nil
  @uri     = nil
  @load_specs_names = {}
end

Instance Method Details

#<=>(other)

Local sorts before ::Gem::Source and after Installed

[ GitHub ]

  
# File 'lib/rubygems/source/local.rb', line 17

def <=>(other)
  case other
  when Gem::Source::Installed,
       Gem::Source::Lock then
    -1
  when Gem::Source::Local then
    0
  when Gem::Source then
    1
  else
    nil
  end
end

#download(spec, cache_dir = nil)

This method is for internal use only.

Raises:

[ GitHub ]

  
# File 'lib/rubygems/source/local.rb', line 113

def download(spec, cache_dir = nil) # :nodoc:
  load_specs :complete

  @specs.each do |name, data|
    return data[0] if data[1].spec == spec
  end

  raise Gem::Exception, "Unable to find file for '#{spec.full_name}'"
end

#fetch_spec(name)

This method is for internal use only.
[ GitHub ]

  
# File 'lib/rubygems/source/local.rb', line 103

def fetch_spec(name) # :nodoc:
  load_specs :complete

  if data = @specs[name]
    data.last.spec
  else
    raise Gem::Exception, "Unable to find spec for #{name.inspect}"
  end
end

#find_gem(gem_name, version = Gem::Requirement.default, prerelease = false)

This method is for internal use only.
[ GitHub ]

  
# File 'lib/rubygems/source/local.rb', line 80

def find_gem(gem_name, version = Gem::Requirement.default, # :nodoc:
             prerelease = false)
  load_specs :complete

  found = []

  @specs.each do |n, data|
    if n.name == gem_name
      s = data[1].spec

      if version.satisfied_by?(s.version)
        if prerelease
          found << s
        elsif !s.version.prerelease? || version.prerelease?
          found << s
        end
      end
    end
  end

  found.max_by {|s| s.version }
end

#inspect

This method is for internal use only.
[ GitHub ]

  
# File 'lib/rubygems/source/local.rb', line 31

def inspect # :nodoc:
  keys = @specs ? @specs.keys.sort : 'NOT LOADED'
  "#<%s specs: %p>" % [self.class, keys]
end

#load_specs(type)

This method is for internal use only.
[ GitHub ]

  
# File 'lib/rubygems/source/local.rb', line 36

def load_specs(type) # :nodoc:
  @load_specs_names[type] ||= begin
    names = []

    @specs = {}

    Dir["*.gem"].each do |file|
      begin
        pkg = Gem::Package.new(file)
      rescue SystemCallError, Gem::Package::FormatError
        # ignore
      else
        tup = pkg.spec.name_tuple
        @specs[tup] = [File.expand_path(file), pkg]

        case type
        when :released
          unless pkg.spec.version.prerelease?
            names << pkg.spec.name_tuple
          end
        when :prerelease
          if pkg.spec.version.prerelease?
            names << pkg.spec.name_tuple
          end
        when :latest
          tup = pkg.spec.name_tuple

          cur = names.find {|x| x.name == tup.name }
          if !cur
            names << tup
          elsif cur.version < tup.version
            names.delete cur
            names << tup
          end
        else
          names << pkg.spec.name_tuple
        end
      end
    end

    names
  end
end

#pretty_print(q)

This method is for internal use only.
[ GitHub ]

  
# File 'lib/rubygems/source/local.rb', line 123

def pretty_print(q) # :nodoc:
  q.group 2, '[Local gems:', ']' do
    q.breakable
    q.seplist @specs.keys do |v|
      q.text v.full_name
    end
  end
end