123456789_123456789_123456789_123456789_123456789_

Class: Gem::Source::SpecificFile

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/specific_file.rb

Overview

A source representing a single .gem file. This is used for installation of local gems.

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

Returns a value representing the “cost” of transforming str1 into str2 Vendored version of DidYouMean::Levenshtein.distance from the ruby/did_you_mean gem @ 1.4.0 github.com/ruby/did_you_mean/blob/2ddf39b874808685965dbc47d344cf6c7651807c/lib/did_you_mean/levenshtein.rb#L7-L37.

#truncate_text, #min3

Constructor Details

.new(file) ⇒ SpecificFile

Creates a new SpecificFile for the gem in file

[ GitHub ]

  
# File 'lib/rubygems/source/specific_file.rb', line 16

def initialize(file)
  @uri = nil
  @path = ::File.expand_path(file)

  @package = Gem::Package.new @path
  @spec = @package.spec
  @name = @spec.name_tuple
end

Instance Attribute Details

#path (readonly)

The path to the gem for this specific file.

[ GitHub ]

  
# File 'lib/rubygems/source/specific_file.rb', line 11

attr_reader :path

#spec (readonly)

The ::Gem::Specification extracted from this .gem.

[ GitHub ]

  
# File 'lib/rubygems/source/specific_file.rb', line 28

attr_reader :spec

Instance Method Details

#<=>(other)

Orders this source against other.

If other is a SpecificFile from a different gem name nil is returned.

If other is a SpecificFile from the same gem name the versions are compared using Version#<=>

Otherwise Gem::Source#<=> is used.

[ GitHub ]

  
# File 'lib/rubygems/source/specific_file.rb', line 61

def <=>(other)
  case other
  when Gem::Source::SpecificFile then
    return nil if @spec.name != other.spec.name

    @spec.version <=> other.spec.version
  else
    super
  end
end

#download(spec, dir = nil)

This method is for internal use only.

Raises:

[ GitHub ]

  
# File 'lib/rubygems/source/specific_file.rb', line 39

def download(spec, dir = nil) # :nodoc:
  return @path if spec == @spec
  raise Gem::Exception, "Unable to download '#{spec.full_name}'"
end

#fetch_spec(name)

This method is for internal use only.

Raises:

[ GitHub ]

  
# File 'lib/rubygems/source/specific_file.rb', line 34

def fetch_spec(name) # :nodoc:
  return @spec if name == @name
  raise Gem::Exception, "Unable to find '#{name}'"
end

#load_specs(*a)

This method is for internal use only.
[ GitHub ]

  
# File 'lib/rubygems/source/specific_file.rb', line 30

def load_specs(*a) # :nodoc:
  [@name]
end

#pretty_print(q)

This method is for internal use only.
[ GitHub ]

  
# File 'lib/rubygems/source/specific_file.rb', line 44

def pretty_print(q) # :nodoc:
  q.group 2, "[SpecificFile:", "]" do
    q.breakable
    q.text @path
  end
end