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

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

Constructor Details

#initialize(file) ⇒ SpecificFile

Creates a new SpecificFile for the gem in file



10
11
12
13
14
15
16
17
# File 'lib/rubygems/source/specific_file.rb', line 10

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

#specObject (readonly)

The Gem::Specification extracted from this .gem.



22
23
24
# File 'lib/rubygems/source/specific_file.rb', line 22

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.



56
57
58
59
60
61
62
63
64
65
# File 'lib/rubygems/source/specific_file.rb', line 56

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:



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

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:



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

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

#load_specs(*a) ⇒ Object

:nodoc:



24
25
26
# File 'lib/rubygems/source/specific_file.rb', line 24

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

#pretty_print(q) ⇒ Object

:nodoc:



39
40
41
42
43
44
# File 'lib/rubygems/source/specific_file.rb', line 39

def pretty_print q # :nodoc:
  q.group 2, '[Local:', ']' do
    q.breakable
    q.text @path
  end
end