Class: Gem::Source::SpecificFile

Inherits:
Gem::Source show all
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

Constants inherited from Gem::Source

FILES

Instance Attribute Summary collapse

Attributes inherited from Gem::Source

#uri

Instance Method Summary collapse

Methods inherited from Gem::Source

#==, #cache_dir, #dependency_resolver_set, #hash, #typo_squatting?, #update_cache?

Methods included from Text

#clean_text, #format_text, #levenshtein_distance, #min3, #truncate_text

Constructor Details

#initialize(file) ⇒ SpecificFile

Creates a new SpecificFile for the gem in file



16
17
18
19
20
21
22
23
# 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

#pathObject (readonly)

The path to the gem for this specific file.



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

def path
  @path
end

#specObject (readonly)

The Gem::Specification extracted from this .gem.



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

def spec
  @spec
end

Instance Method Details

#<=>(other) ⇒ Object

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 Gem::Version#<=>

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



61
62
63
64
65
66
67
68
69
70
# 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) ⇒ Object

:nodoc:

Raises:



39
40
41
42
# 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) ⇒ Object

:nodoc:

Raises:



34
35
36
37
# 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) ⇒ Object

:nodoc:



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

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

#pretty_print(q) ⇒ Object

:nodoc:



44
45
46
47
48
49
# 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