Class: Bundler::Resolver::SpecGroup

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

Constant Summary

Constant Summary

Constants included from GemHelpers

GemHelpers::GENERICS, GemHelpers::GENERIC_CACHE

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from GemHelpers

#generic

Constructor Details

#initialize(a) ⇒ SpecGroup



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

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



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

def activated
  @activated
end

#required_byObject (readonly)

Returns the value of attribute required_by



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

def required_by
  @required_by
end

Instance Method Details

#activate_platform(platform) ⇒ Object



108
109
110
111
112
113
114
115
116
# File 'lib/bundler/resolver.rb', line 108

def activate_platform(platform)
  unless @activated.include?(platform)
    if for?(platform, nil)
      @activated << platform
      return __dependencies[platform] || []
    end
  end
  []
end

#dependencies_for_activated_platformsObject



144
145
146
# File 'lib/bundler/resolver.rb', line 144

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

#for?(platform, required_ruby_version) ⇒ Boolean



130
131
132
133
134
135
136
137
138
# File 'lib/bundler/resolver.rb', line 130

def for?(platform, required_ruby_version)
  if spec = @specs[platform]
    if required_ruby_version && spec.respond_to?(:required_ruby_version) && spec_required_ruby_version = spec.required_ruby_version
      spec_required_ruby_version.satisfied_by?(required_ruby_version)
    else
      true
    end
  end
end

#initialize_copy(o) ⇒ Object



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

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

#nameObject



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

def name
  @name ||= first.name
end

#platforms_for_dependency_named(dependency) ⇒ Object



148
149
150
# File 'lib/bundler/resolver.rb', line 148

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

#sourceObject



126
127
128
# File 'lib/bundler/resolver.rb', line 126

def source
  @source ||= first.source
end

#to_sObject



140
141
142
# File 'lib/bundler/resolver.rb', line 140

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

#to_specsObject



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

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



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

def version
  @version ||= first.version
end