Class: Gem::Resolver::LockSpecification

Inherits:
Specification show all
Defined in:
lib/rubygems/resolver/lock_specification.rb

Overview

The LockSpecification comes from a lockfile (Gem::RequestSet::Lockfile).

A LockSpecification’s dependency information is pre-filled from the lockfile.

Instance Attribute Summary collapse

Attributes inherited from Specification

#dependencies, #name, #platform, #required_ruby_version, #required_rubygems_version, #set, #source, #version

Instance Method Summary collapse

Methods inherited from Specification

#download, #fetch_development_dependencies, #full_name, #installable_platform?, #local?

Constructor Details

#initialize(set, name, version, sources, platform) ⇒ LockSpecification

Returns a new instance of LockSpecification.



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/rubygems/resolver/lock_specification.rb', line 12

def initialize(set, name, version, sources, platform)
  super()

  @name     = name
  @platform = platform
  @set      = set
  @source   = sources.first
  @sources  = sources
  @version  = version

  @dependencies = []
  @spec         = nil
end

Instance Attribute Details

#sourcesObject (readonly)

Returns the value of attribute sources.



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

def sources
  @sources
end

Instance Method Details

#add_dependency(dependency) ⇒ Object

Adds dependency from the lockfile to this specification



44
45
46
# File 'lib/rubygems/resolver/lock_specification.rb', line 44

def add_dependency(dependency) # :nodoc:
  @dependencies << dependency
end

#install(options = {}) ⇒ Object

This is a null install as a locked specification is considered installed. options are ignored.



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

def install(options = {})
  destination = options[:install_dir] || Gem.dir

  if File.exist? File.join(destination, "specifications", spec.spec_name)
    yield nil
    return
  end

  super
end

#pretty_print(q) ⇒ Object

:nodoc:



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

def pretty_print(q) # :nodoc:
  q.group 2, "[LockSpecification", "]" do
    q.breakable
    q.text "name: #{@name}"

    q.breakable
    q.text "version: #{@version}"

    unless @platform == Gem::Platform::RUBY
      q.breakable
      q.text "platform: #{@platform}"
    end

    unless @dependencies.empty?
      q.breakable
      q.text "dependencies:"
      q.breakable
      q.pp @dependencies
    end
  end
end

#specObject

A specification constructed from the lockfile is returned



73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/rubygems/resolver/lock_specification.rb', line 73

def spec
  @spec ||= Gem::Specification.find do |spec|
    spec.name == @name && spec.version == @version
  end

  @spec ||= Gem::Specification.new do |s|
    s.name     = @name
    s.version  = @version
    s.platform = @platform

    s.dependencies.concat @dependencies
  end
end