2015-12-16 00:07:31 -05:00
|
|
|
# frozen_string_literal: false
|
2013-07-09 19:21:36 -04:00
|
|
|
##
|
|
|
|
# Used Internally. Wraps a Dependency object to also track which spec
|
|
|
|
# contained the Dependency.
|
|
|
|
|
2013-11-18 19:34:13 -05:00
|
|
|
class Gem::Resolver::DependencyRequest
|
2013-07-09 19:21:36 -04:00
|
|
|
|
2013-11-25 14:14:49 -05:00
|
|
|
##
|
|
|
|
# The wrapped Gem::Dependency
|
|
|
|
|
2013-07-09 19:21:36 -04:00
|
|
|
attr_reader :dependency
|
|
|
|
|
2013-11-25 14:14:49 -05:00
|
|
|
##
|
|
|
|
# The request for this dependency.
|
|
|
|
|
2013-07-09 19:21:36 -04:00
|
|
|
attr_reader :requester
|
|
|
|
|
2013-11-25 14:14:49 -05:00
|
|
|
##
|
|
|
|
# Creates a new DependencyRequest for +dependency+ from +requester+.
|
|
|
|
# +requester may be nil if the request came from a user.
|
|
|
|
|
|
|
|
def initialize dependency, requester
|
|
|
|
@dependency = dependency
|
|
|
|
@requester = requester
|
2013-07-09 19:21:36 -04:00
|
|
|
end
|
|
|
|
|
2013-11-25 14:14:49 -05:00
|
|
|
def == other # :nodoc:
|
2013-07-09 19:21:36 -04:00
|
|
|
case other
|
|
|
|
when Gem::Dependency
|
|
|
|
@dependency == other
|
2013-11-18 19:34:13 -05:00
|
|
|
when Gem::Resolver::DependencyRequest
|
2013-07-09 19:21:36 -04:00
|
|
|
@dependency == other.dependency && @requester == other.requester
|
|
|
|
else
|
|
|
|
false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-11-25 14:14:49 -05:00
|
|
|
##
|
2014-09-13 23:30:02 -04:00
|
|
|
# Is this dependency a development dependency?
|
|
|
|
|
|
|
|
def development?
|
|
|
|
@dependency.type == :development
|
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# Does this dependency request match +spec+?
|
|
|
|
#
|
|
|
|
# NOTE: #match? only matches prerelease versions when #dependency is a
|
|
|
|
# prerelease dependency.
|
|
|
|
|
|
|
|
def match? spec, allow_prerelease = false
|
|
|
|
@dependency.match? spec, nil, allow_prerelease
|
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# Does this dependency request match +spec+?
|
|
|
|
#
|
|
|
|
# NOTE: #matches_spec? matches prerelease versions. See also #match?
|
2013-11-25 14:14:49 -05:00
|
|
|
|
2013-07-09 19:21:36 -04:00
|
|
|
def matches_spec?(spec)
|
|
|
|
@dependency.matches_spec? spec
|
|
|
|
end
|
|
|
|
|
2013-11-25 14:14:49 -05:00
|
|
|
##
|
|
|
|
# The name of the gem this dependency request is requesting.
|
|
|
|
|
2013-07-09 19:21:36 -04:00
|
|
|
def name
|
|
|
|
@dependency.name
|
|
|
|
end
|
|
|
|
|
2015-07-01 17:50:14 -04:00
|
|
|
def type
|
|
|
|
@dependency.type
|
|
|
|
end
|
|
|
|
|
2013-11-25 14:14:49 -05:00
|
|
|
##
|
2013-11-10 12:51:40 -05:00
|
|
|
# Indicate that the request is for a gem explicitly requested by the user
|
2013-11-25 14:14:49 -05:00
|
|
|
|
2013-11-10 12:51:40 -05:00
|
|
|
def explicit?
|
|
|
|
@requester.nil?
|
|
|
|
end
|
|
|
|
|
2013-11-25 14:14:49 -05:00
|
|
|
##
|
|
|
|
# Indicate that the request is for a gem requested as a dependency of
|
|
|
|
# another gem
|
|
|
|
|
2013-11-10 12:51:40 -05:00
|
|
|
def implicit?
|
|
|
|
!explicit?
|
|
|
|
end
|
|
|
|
|
2013-11-25 14:14:49 -05:00
|
|
|
##
|
2013-11-10 12:51:40 -05:00
|
|
|
# Return a String indicating who caused this request to be added (only
|
|
|
|
# valid for implicit requests)
|
2013-11-25 14:14:49 -05:00
|
|
|
|
2013-11-10 12:51:40 -05:00
|
|
|
def request_context
|
|
|
|
@requester ? @requester.request : "(unknown)"
|
|
|
|
end
|
|
|
|
|
2013-07-09 19:21:36 -04:00
|
|
|
def pretty_print q # :nodoc:
|
|
|
|
q.group 2, '[Dependency request ', ']' do
|
|
|
|
q.breakable
|
|
|
|
q.text @dependency.to_s
|
|
|
|
|
|
|
|
q.breakable
|
|
|
|
q.text ' requested by '
|
|
|
|
q.pp @requester
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-11-25 14:14:49 -05:00
|
|
|
##
|
|
|
|
# The version requirement for this dependency request
|
|
|
|
|
2013-11-10 12:51:40 -05:00
|
|
|
def requirement
|
|
|
|
@dependency.requirement
|
|
|
|
end
|
|
|
|
|
2013-07-09 19:21:36 -04:00
|
|
|
def to_s # :nodoc:
|
|
|
|
@dependency.to_s
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|