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

  @required_by = []
  @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



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

def ==(other)
  return unless other.is_a?(SpecGroup)
  name == other.name &&
    version == other.version &&
    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

#dependencies_for_activated_platformsObject



50
51
52
53
54
55
56
# File 'lib/bundler/resolver/spec_group.rb', line 50

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)


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

def eql?(other)
  name.eql?(other.name) &&
    version.eql?(other.version) &&
    source.eql?(other.source)
end

#for?(platform) ⇒ Boolean

Returns:

  • (Boolean)


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

def for?(platform)
  spec = @specs[platform]
  !spec.nil?
end

#hashObject



75
76
77
# File 'lib/bundler/resolver/spec_group.rb', line 75

def hash
  to_s.hash ^ source.hash
end

#platforms_for_dependency_named(dependency) ⇒ Object



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

def platforms_for_dependency_named(dependency)
  __dependencies.select {|_, deps| deps.map(&:name).include? dependency }.keys
end

#to_sObject



46
47
48
# File 'lib/bundler/resolver/spec_group.rb', line 46

def to_s
  @to_s ||= "#{name} (#{version})"
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
end