Class: Gem::Resolver::ActivationRequest

Inherits:
Object
  • Object
show all
Defined in:
lib/rubygems/resolver/activation_request.rb

Overview

Specifies a Specification object that should be activated. Also contains a dependency that was used to introduce this activation.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(spec, request, others_possible = true) ⇒ ActivationRequest

Creates a new ActivationRequest that will activate spec. The parent request is used to provide diagnostics in case of conflicts.

others_possible indicates that other specifications may also match this activation request.



24
25
26
27
28
# File 'lib/rubygems/resolver/activation_request.rb', line 24

def initialize spec, request, others_possible = true
  @spec = spec
  @request = request
  @others_possible = others_possible
end

Instance Attribute Details

#requestObject (readonly)

The parent request for this activation request.



10
11
12
# File 'lib/rubygems/resolver/activation_request.rb', line 10

def request
  @request
end

#specObject (readonly)

The specification to be activated.



15
16
17
# File 'lib/rubygems/resolver/activation_request.rb', line 15

def spec
  @spec
end

Instance Method Details

#==(other) ⇒ Object

:nodoc:



30
31
32
33
34
35
36
37
38
39
# File 'lib/rubygems/resolver/activation_request.rb', line 30

def == other # :nodoc:
  case other
  when Gem::Specification
    @spec == other
  when Gem::Resolver::ActivationRequest
    @spec == other.spec && @request == other.request
  else
    false
  end
end

#download(path) ⇒ Object

Downloads a gem at path and returns the file path.



44
45
46
47
48
49
50
51
52
53
54
# File 'lib/rubygems/resolver/activation_request.rb', line 44

def download path
  if @spec.respond_to? :source
    source = @spec.source
  else
    source = Gem.sources.first
  end

  Gem.ensure_gem_subdirectories path

  source.download full_spec, path
end

#full_nameObject

The full name of the specification to be activated.



59
60
61
# File 'lib/rubygems/resolver/activation_request.rb', line 59

def full_name
  @spec.full_name
end

#full_specObject

The Gem::Specification for this activation request.



66
67
68
# File 'lib/rubygems/resolver/activation_request.rb', line 66

def full_spec
  Gem::Specification === @spec ? @spec : @spec.spec
end

#inspectObject

:nodoc:



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/rubygems/resolver/activation_request.rb', line 70

def inspect # :nodoc:
  others =
    case @others_possible
    when true then # TODO remove at RubyGems 3
      ' (others possible)'
    when false then # TODO remove at RubyGems 3
      nil
    else
      unless @others_possible.empty? then
        others = @others_possible.map { |s| s.full_name }
        " (others possible: #{others.join ', '})"
      end
    end

  '#<%s for %p from %s%s>' % [
    self.class, @spec, @request, others
  ]
end

#installed?Boolean

True if the requested gem has already been installed.

Returns:

  • (Boolean)


92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/rubygems/resolver/activation_request.rb', line 92

def installed?
  case @spec
  when Gem::Resolver::VendorSpecification then
    true
  else
    this_spec = full_spec

    Gem::Specification.any? do |s|
      s == this_spec
    end
  end
end

#nameObject

The name of this activation request’s specification



108
109
110
# File 'lib/rubygems/resolver/activation_request.rb', line 108

def name
  @spec.name
end

#others_possible?Boolean

Indicate if this activation is one of a set of possible requests for the same Dependency request.

Returns:

  • (Boolean)


116
117
118
119
120
121
122
123
# File 'lib/rubygems/resolver/activation_request.rb', line 116

def others_possible?
  case @others_possible
  when true, false then
    @others_possible
  else
    not @others_possible.empty?
  end
end

#parentObject

Return the ActivationRequest that contained the dependency that we were activated for.



129
130
131
# File 'lib/rubygems/resolver/activation_request.rb', line 129

def parent
  @request.requester
end

#pretty_print(q) ⇒ Object

:nodoc:



133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/rubygems/resolver/activation_request.rb', line 133

def pretty_print q # :nodoc:
  q.group 2, '[Activation request', ']' do
    q.breakable
    q.pp @spec

    q.breakable
    q.text ' for '
    q.pp @request

    case @others_possible
    when false then
    when true then
      q.breakable
      q.text 'others possible'
    else
      unless @others_possible.empty? then
        q.breakable
        q.text 'others '
        q.pp @others_possible.map { |s| s.full_name }
      end
    end
  end
end

#versionObject

The version of this activation request’s specification



160
161
162
# File 'lib/rubygems/resolver/activation_request.rb', line 160

def version
  @spec.version
end