Class: Bundler::SourceMap

Inherits:
Object
  • Object
show all
Defined in:
lib/bundler/source_map.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sources, dependencies, locked_specs) ⇒ SourceMap

Returns a new instance of SourceMap.


7
8
9
10
11
# File 'lib/bundler/source_map.rb', line 7

def initialize(sources, dependencies, locked_specs)
  @sources = sources
  @dependencies = dependencies
  @locked_specs = locked_specs
end

Instance Attribute Details

#dependenciesObject (readonly)

Returns the value of attribute dependencies.


5
6
7
# File 'lib/bundler/source_map.rb', line 5

def dependencies
  @dependencies
end

#locked_specsObject (readonly)

Returns the value of attribute locked_specs.


5
6
7
# File 'lib/bundler/source_map.rb', line 5

def locked_specs
  @locked_specs
end

#sourcesObject (readonly)

Returns the value of attribute sources.


5
6
7
# File 'lib/bundler/source_map.rb', line 5

def sources
  @sources
end

Instance Method Details

#all_requirementsObject


17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/bundler/source_map.rb', line 17

def all_requirements
  requirements = direct_requirements.dup

  unmet_deps = sources.non_default_explicit_sources.map do |source|
    (source.spec_names - pinned_spec_names).each do |indirect_dependency_name|
      previous_source = requirements[indirect_dependency_name]
      if previous_source.nil?
        requirements[indirect_dependency_name] = source
      else
        no_ambiguous_sources = Bundler.feature_flag.bundler_3_mode?

        msg = ["The gem '#{indirect_dependency_name}' was found in multiple relevant sources."]
        msg.concat [previous_source, source].map {|s| "  * #{s}" }.sort
        msg << "You #{no_ambiguous_sources ? :must : :should} add this gem to the source block for the source you wish it to be installed from."
        msg = msg.join("\n")

        raise SecurityError, msg if no_ambiguous_sources
        Bundler.ui.warn "Warning: #{msg}"
      end
    end

    source.unmet_deps
  end

  sources.default_source.add_dependency_names(unmet_deps.flatten - requirements.keys)

  requirements
end

#direct_requirementsObject


46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/bundler/source_map.rb', line 46

def direct_requirements
  @direct_requirements ||= begin
    requirements = {}
    default = sources.default_source
    dependencies.each do |dep|
      dep_source = dep.source || default
      dep_source.add_dependency_names(dep.name)
      requirements[dep.name] = dep_source
    end
    requirements
  end
end

#locked_requirementsObject


59
60
61
62
63
64
65
66
67
68
69
# File 'lib/bundler/source_map.rb', line 59

def locked_requirements
  @locked_requirements ||= begin
    requirements = {}
    locked_specs.each do |locked_spec|
      source = locked_spec.source
      source.add_dependency_names(locked_spec.name)
      requirements[locked_spec.name] = source
    end
    requirements
  end
end

#pinned_spec_names(skip = nil) ⇒ Object


13
14
15
# File 'lib/bundler/source_map.rb', line 13

def pinned_spec_names(skip = nil)
  direct_requirements.reject {|_, source| source == skip }.keys
end