Class: Bundler::Resolver::SpecGroup

Inherits:
Array
  • Object
show all
Includes:
GemHelpers
Defined in:
lib/bundler/resolver.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

Constructor Details

#initialize(a) ⇒ SpecGroup

Returns a new instance of SpecGroup



76
77
78
79
80
81
82
83
84
85
86
# File 'lib/bundler/resolver.rb', line 76

def initialize(a)
  super
  @required_by  = []
  @activated    = []
  @dependencies = nil
  @specs        = {}

  ALL.each do |p|
    @specs[p] = reverse.find {|s| s.match_platform(p) }
  end
end

Instance Attribute Details

#activatedObject (readonly)

Returns the value of attribute activated



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

def activated
  @activated
end

#required_byObject (readonly)

Returns the value of attribute required_by



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

def required_by
  @required_by
end

Instance Method Details

#activate_platform!(platform) ⇒ Object



109
110
111
# File 'lib/bundler/resolver.rb', line 109

def activate_platform!(platform)
  @activated << platform if !@activated.include?(platform) && for?(platform, nil)
end

#dependencies_for_activated_platformsObject



142
143
144
# File 'lib/bundler/resolver.rb', line 142

def dependencies_for_activated_platforms
  @activated.map {|p| __dependencies[p] }.flatten
end

#for?(platform, ruby_version) ⇒ Boolean

Returns:

  • (Boolean)


125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/bundler/resolver.rb', line 125

def for?(platform, ruby_version)
  spec = @specs[platform]
  return false unless spec

  return true if ruby_version.nil?
  # Only allow endpoint specifications since they won't hit the network to
  # fetch the full gemspec when calling required_ruby_version
  return true if !spec.is_a?(EndpointSpecification) && !spec.is_a?(Gem::Specification)
  return true if spec.required_ruby_version.nil?

  spec.required_ruby_version.satisfied_by?(ruby_version.to_gem_version_with_patchlevel)
end

#initialize_copy(o) ⇒ Object



88
89
90
91
92
# File 'lib/bundler/resolver.rb', line 88

def initialize_copy(o)
  super
  @required_by = o.required_by.dup
  @activated   = o.activated.dup
end

#nameObject



113
114
115
# File 'lib/bundler/resolver.rb', line 113

def name
  @name ||= first.name
end

#platforms_for_dependency_named(dependency) ⇒ Object



146
147
148
# File 'lib/bundler/resolver.rb', line 146

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

#sourceObject



121
122
123
# File 'lib/bundler/resolver.rb', line 121

def source
  @source ||= first.source
end

#to_sObject



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

def to_s
  "#{name} (#{version})"
end

#to_specsObject



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

def to_specs
  specs = {}

  @activated.each do |p|
    next unless s = @specs[p]
    platform = generic(Gem::Platform.new(s.platform))
    next if specs[platform]

    lazy_spec = LazySpecification.new(name, version, platform, source)
    lazy_spec.dependencies.replace s.dependencies
    specs[platform] = lazy_spec
  end
  specs.values
end

#versionObject



117
118
119
# File 'lib/bundler/resolver.rb', line 117

def version
  @version ||= first.version
end