Class: Bundler::Resolver::SpecGroup

Inherits:
Object
  • Object
show all
Includes:
GemHelpers
Defined in:
lib/bundler/resolver/spec_group.rb

Constant Summary

Constants included from GemHelpers

GemHelpers::GENERICS, GemHelpers::GENERIC_CACHE

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from GemHelpers

generic, generic_local_platform, platform_specificity_match, select_best_platform_match

Constructor Details

#initialize(all_specs) ⇒ SpecGroup

Returns a new instance of SpecGroup.

Raises:

  • (ArgumentError)


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

def initialize(all_specs)
  @all_specs = all_specs
  raise ArgumentError, "cannot initialize with an empty value" unless exemplary_spec = all_specs.first
  @name = exemplary_spec.name
  @version = exemplary_spec.version
  @source = exemplary_spec.source

  @activated_platforms = []
  @dependencies = nil
  @specs        = Hash.new do |specs, platform|
    specs[platform] = select_best_platform_match(all_specs, platform)
  end
  @ignores_bundler_dependencies = true
end

Instance Attribute Details

#ignores_bundler_dependenciesObject

Returns the value of attribute ignores_bundler_dependencies.



9
10
11
# File 'lib/bundler/resolver/spec_group.rb', line 9

def ignores_bundler_dependencies
  @ignores_bundler_dependencies
end

#nameObject

Returns the value of attribute name.



8
9
10
# File 'lib/bundler/resolver/spec_group.rb', line 8

def name
  @name
end

#sourceObject

Returns the value of attribute source.



8
9
10
# File 'lib/bundler/resolver/spec_group.rb', line 8

def source
  @source
end

#versionObject

Returns the value of attribute version.



8
9
10
# File 'lib/bundler/resolver/spec_group.rb', line 8

def version
  @version
end

Instance Method Details

#==(other) ⇒ Object



70
71
72
73
74
75
76
# File 'lib/bundler/resolver/spec_group.rb', line 70

def ==(other)
  return unless other.is_a?(SpecGroup)
  name == other.name &&
    version == other.version &&
    sorted_activated_platforms == other.sorted_activated_platforms &&
    source == other.source
end

#activate_platform!(platform) ⇒ Object



35
36
37
38
39
# File 'lib/bundler/resolver/spec_group.rb', line 35

def activate_platform!(platform)
  return unless for?(platform)
  return if @activated_platforms.include?(platform)
  @activated_platforms << platform
end

#copy_for(platform) ⇒ Object



41
42
43
44
45
46
47
# File 'lib/bundler/resolver/spec_group.rb', line 41

def copy_for(platform)
  copied_sg = self.class.new(@all_specs)
  copied_sg.ignores_bundler_dependencies = @ignores_bundler_dependencies
  return nil unless copied_sg.for?(platform)
  copied_sg.activate_platform!(platform)
  copied_sg
end

#dependencies_for_activated_platformsObject



62
63
64
65
66
67
68
# File 'lib/bundler/resolver/spec_group.rb', line 62

def dependencies_for_activated_platforms
  dependencies = @activated_platforms.map {|p| __dependencies[p] }
   = @activated_platforms.map do |platform|
    (@specs[platform], platform)
  end
  dependencies.concat().flatten
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


78
79
80
81
82
83
84
# File 'lib/bundler/resolver/spec_group.rb', line 78

def eql?(other)
  return unless other.is_a?(SpecGroup)
  name.eql?(other.name) &&
    version.eql?(other.version) &&
    sorted_activated_platforms.eql?(other.sorted_activated_platforms) &&
    source.eql?(other.source)
end

#for?(platform) ⇒ Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/bundler/resolver/spec_group.rb', line 53

def for?(platform)
  !spec_for(platform).nil?
end

#hashObject



86
87
88
# File 'lib/bundler/resolver/spec_group.rb', line 86

def hash
  name.hash ^ version.hash ^ sorted_activated_platforms.hash ^ source.hash
end

#spec_for(platform) ⇒ Object



49
50
51
# File 'lib/bundler/resolver/spec_group.rb', line 49

def spec_for(platform)
  @specs[platform]
end

#to_sObject



57
58
59
60
# File 'lib/bundler/resolver/spec_group.rb', line 57

def to_s
  activated_platforms_string = sorted_activated_platforms.join(", ")
  "#{name} (#{version}) (#{activated_platforms_string})"
end

#to_specsObject



26
27
28
29
30
31
32
33
# File 'lib/bundler/resolver/spec_group.rb', line 26

def to_specs
  @activated_platforms.map do |p|
    next unless s = @specs[p]
    lazy_spec = LazySpecification.new(name, version, s.platform, source)
    lazy_spec.dependencies.replace s.dependencies
    lazy_spec
  end.compact.uniq
end