2016-02-01 07:43:26 -05:00
|
|
|
# frozen_string_literal: true
|
2013-11-18 19:34:13 -05:00
|
|
|
##
|
|
|
|
# A source representing a single .gem file. This is used for installation of
|
|
|
|
# local gems.
|
|
|
|
|
2013-07-09 19:21:36 -04:00
|
|
|
class Gem::Source::SpecificFile < Gem::Source
|
2013-11-18 19:34:13 -05:00
|
|
|
|
2014-09-13 23:30:02 -04:00
|
|
|
##
|
|
|
|
# The path to the gem for this specific file.
|
|
|
|
|
|
|
|
attr_reader :path
|
|
|
|
|
2013-11-18 19:34:13 -05:00
|
|
|
##
|
|
|
|
# Creates a new SpecificFile for the gem in +file+
|
|
|
|
|
2013-07-09 19:21:36 -04:00
|
|
|
def initialize(file)
|
|
|
|
@uri = nil
|
|
|
|
@path = ::File.expand_path(file)
|
|
|
|
|
|
|
|
@package = Gem::Package.new @path
|
|
|
|
@spec = @package.spec
|
|
|
|
@name = @spec.name_tuple
|
|
|
|
end
|
|
|
|
|
2013-11-18 19:34:13 -05:00
|
|
|
##
|
|
|
|
# The Gem::Specification extracted from this .gem.
|
|
|
|
|
2013-07-09 19:21:36 -04:00
|
|
|
attr_reader :spec
|
|
|
|
|
2013-11-18 19:34:13 -05:00
|
|
|
def load_specs *a # :nodoc:
|
2013-07-09 19:21:36 -04:00
|
|
|
[@name]
|
|
|
|
end
|
|
|
|
|
2013-11-18 19:34:13 -05:00
|
|
|
def fetch_spec name # :nodoc:
|
2013-07-09 19:21:36 -04:00
|
|
|
return @spec if name == @name
|
|
|
|
raise Gem::Exception, "Unable to find '#{name}'"
|
|
|
|
@spec
|
|
|
|
end
|
|
|
|
|
2013-11-18 19:34:13 -05:00
|
|
|
def download spec, dir = nil # :nodoc:
|
2013-07-09 19:21:36 -04:00
|
|
|
return @path if spec == @spec
|
|
|
|
raise Gem::Exception, "Unable to download '#{spec.full_name}'"
|
|
|
|
end
|
|
|
|
|
2013-08-26 16:24:51 -04:00
|
|
|
def pretty_print q # :nodoc:
|
2014-09-13 23:30:02 -04:00
|
|
|
q.group 2, '[SpecificFile:', ']' do
|
2013-08-26 16:24:51 -04:00
|
|
|
q.breakable
|
|
|
|
q.text @path
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# 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.
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2013-07-09 19:21:36 -04:00
|
|
|
end
|