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) ⇒ ActivationRequest

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


21
22
23
24
# File 'lib/rubygems/resolver/activation_request.rb', line 21

def initialize(spec, request)
  @spec = spec
  @request = request
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:


26
27
28
29
30
31
32
33
34
35
# File 'lib/rubygems/resolver/activation_request.rb', line 26

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

#development?Boolean

Is this activation request for a development dependency?

Returns:

  • (Boolean)

40
41
42
# File 'lib/rubygems/resolver/activation_request.rb', line 40

def development?
  @request.development?
end

#download(path) ⇒ Object

Downloads a gem at path and returns the file path.


47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/rubygems/resolver/activation_request.rb', line 47

def download(path)
  Gem.ensure_gem_subdirectories path

  if @spec.respond_to? :sources
    exception = nil
    path = @spec.sources.find do |source|
      begin
        source.download full_spec, path
      rescue exception
      end
    end
    return path      if path
    raise  exception if exception

  elsif @spec.respond_to? :source
    source = @spec.source
    source.download full_spec, path

  else
    source = Gem.sources.first
    source.download full_spec, path
  end
end

#full_nameObject Also known as: to_s

The full name of the specification to be activated.


74
75
76
# File 'lib/rubygems/resolver/activation_request.rb', line 74

def full_name
  name_tuple.full_name
end

#full_specObject

The Gem::Specification for this activation request.


83
84
85
# File 'lib/rubygems/resolver/activation_request.rb', line 83

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

#inspectObject

:nodoc:


87
88
89
90
91
# File 'lib/rubygems/resolver/activation_request.rb', line 87

def inspect # :nodoc:
  '#<%s for %p from %s>' % [
    self.class, @spec, @request
  ]
end

#installed?Boolean

True if the requested gem has already been installed.

Returns:

  • (Boolean)

96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/rubygems/resolver/activation_request.rb', line 96

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


112
113
114
# File 'lib/rubygems/resolver/activation_request.rb', line 112

def name
  @spec.name
end

#parentObject

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


120
121
122
# File 'lib/rubygems/resolver/activation_request.rb', line 120

def parent
  @request.requester
end

#platformObject

The platform of this activation request's specification


145
146
147
# File 'lib/rubygems/resolver/activation_request.rb', line 145

def platform
  @spec.platform
end

#pretty_print(q) ⇒ Object

:nodoc:


124
125
126
127
128
129
130
131
132
133
# File 'lib/rubygems/resolver/activation_request.rb', line 124

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

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

#versionObject

The version of this activation request's specification


138
139
140
# File 'lib/rubygems/resolver/activation_request.rb', line 138

def version
  @spec.version
end