rubygems-update 3.2.30 → 3.2.31

Sign up to get free protection for your applications and to get access to all the features.
Files changed (99) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +20 -0
  3. data/Manifest.txt +18 -0
  4. data/bundler/CHANGELOG.md +17 -0
  5. data/bundler/lib/bundler/build_metadata.rb +2 -2
  6. data/bundler/lib/bundler/cli/gem.rb +68 -7
  7. data/bundler/lib/bundler/cli.rb +3 -1
  8. data/bundler/lib/bundler/definition.rb +5 -4
  9. data/bundler/lib/bundler/lockfile_parser.rb +1 -0
  10. data/bundler/lib/bundler/man/bundle-add.1 +1 -1
  11. data/bundler/lib/bundler/man/bundle-binstubs.1 +1 -1
  12. data/bundler/lib/bundler/man/bundle-cache.1 +1 -1
  13. data/bundler/lib/bundler/man/bundle-check.1 +1 -1
  14. data/bundler/lib/bundler/man/bundle-clean.1 +1 -1
  15. data/bundler/lib/bundler/man/bundle-config.1 +3 -3
  16. data/bundler/lib/bundler/man/bundle-config.1.ronn +2 -2
  17. data/bundler/lib/bundler/man/bundle-doctor.1 +1 -1
  18. data/bundler/lib/bundler/man/bundle-exec.1 +1 -1
  19. data/bundler/lib/bundler/man/bundle-gem.1 +14 -1
  20. data/bundler/lib/bundler/man/bundle-gem.1.ronn +16 -0
  21. data/bundler/lib/bundler/man/bundle-info.1 +1 -1
  22. data/bundler/lib/bundler/man/bundle-init.1 +1 -1
  23. data/bundler/lib/bundler/man/bundle-inject.1 +1 -1
  24. data/bundler/lib/bundler/man/bundle-install.1 +1 -1
  25. data/bundler/lib/bundler/man/bundle-list.1 +1 -1
  26. data/bundler/lib/bundler/man/bundle-lock.1 +1 -1
  27. data/bundler/lib/bundler/man/bundle-open.1 +1 -1
  28. data/bundler/lib/bundler/man/bundle-outdated.1 +1 -1
  29. data/bundler/lib/bundler/man/bundle-platform.1 +1 -1
  30. data/bundler/lib/bundler/man/bundle-pristine.1 +1 -1
  31. data/bundler/lib/bundler/man/bundle-remove.1 +1 -1
  32. data/bundler/lib/bundler/man/bundle-show.1 +1 -1
  33. data/bundler/lib/bundler/man/bundle-update.1 +1 -1
  34. data/bundler/lib/bundler/man/bundle-viz.1 +1 -1
  35. data/bundler/lib/bundler/man/bundle.1 +1 -1
  36. data/bundler/lib/bundler/man/gemfile.5 +1 -1
  37. data/bundler/lib/bundler/runtime.rb +1 -1
  38. data/bundler/lib/bundler/source/git/git_proxy.rb +5 -2
  39. data/bundler/lib/bundler/source/rubygems.rb +1 -1
  40. data/bundler/lib/bundler/spec_set.rb +1 -1
  41. data/bundler/lib/bundler/templates/newgem/Gemfile.tt +5 -2
  42. data/bundler/lib/bundler/templates/newgem/Rakefile.tt +5 -1
  43. data/bundler/lib/bundler/templates/newgem/newgem.gemspec.tt +12 -12
  44. data/bundler/lib/bundler/templates/newgem/standard.yml.tt +4 -0
  45. data/bundler/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph.rb +2 -2
  46. data/bundler/lib/bundler/vendor/tsort/LICENSE.txt +22 -0
  47. data/bundler/lib/bundler/vendor/tsort/lib/tsort.rb +453 -0
  48. data/bundler/lib/bundler/vendored_tsort.rb +4 -0
  49. data/bundler/lib/bundler/version.rb +1 -1
  50. data/lib/rubygems/command.rb +4 -4
  51. data/lib/rubygems/commands/cert_command.rb +6 -6
  52. data/lib/rubygems/commands/fetch_command.rb +1 -1
  53. data/lib/rubygems/commands/server_command.rb +3 -3
  54. data/lib/rubygems/commands/setup_command.rb +64 -55
  55. data/lib/rubygems/commands/uninstall_command.rb +1 -1
  56. data/lib/rubygems/commands/update_command.rb +1 -1
  57. data/lib/rubygems/dependency_list.rb +2 -2
  58. data/lib/rubygems/ext/builder.rb +6 -5
  59. data/lib/rubygems/ext/cmake_builder.rb +1 -1
  60. data/lib/rubygems/install_update_options.rb +2 -2
  61. data/lib/rubygems/installer.rb +30 -5
  62. data/lib/rubygems/local_remote_options.rb +3 -3
  63. data/lib/rubygems/optparse/COPYING +56 -0
  64. data/lib/rubygems/optparse/lib/optionparser.rb +2 -0
  65. data/lib/rubygems/optparse/lib/optparse/ac.rb +54 -0
  66. data/lib/rubygems/optparse/lib/optparse/date.rb +18 -0
  67. data/lib/rubygems/optparse/lib/optparse/kwargs.rb +22 -0
  68. data/lib/rubygems/optparse/lib/optparse/shellwords.rb +7 -0
  69. data/lib/rubygems/optparse/lib/optparse/time.rb +11 -0
  70. data/lib/rubygems/optparse/lib/optparse/uri.rb +7 -0
  71. data/lib/rubygems/optparse/lib/optparse/version.rb +71 -0
  72. data/lib/rubygems/optparse/lib/optparse.rb +2230 -0
  73. data/lib/rubygems/optparse.rb +3 -0
  74. data/lib/rubygems/request_set.rb +2 -2
  75. data/lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph.rb +2 -2
  76. data/lib/rubygems/security_option.rb +3 -3
  77. data/lib/rubygems/specification.rb +9 -5
  78. data/lib/rubygems/tsort/LICENSE.txt +22 -0
  79. data/lib/rubygems/tsort/lib/tsort.rb +454 -0
  80. data/lib/rubygems/tsort.rb +3 -0
  81. data/lib/rubygems/util/licenses.rb +2 -0
  82. data/lib/rubygems/version_option.rb +2 -2
  83. data/lib/rubygems.rb +1 -1
  84. data/rubygems-update.gemspec +1 -1
  85. data/test/rubygems/encrypted_private_key.pem +26 -26
  86. data/test/rubygems/helper.rb +22 -18
  87. data/test/rubygems/test_gem_command.rb +1 -1
  88. data/test/rubygems/test_gem_commands_cert_command.rb +8 -8
  89. data/test/rubygems/test_gem_commands_fetch_command.rb +36 -0
  90. data/test/rubygems/test_gem_commands_server_command.rb +3 -3
  91. data/test/rubygems/test_gem_commands_setup_command.rb +50 -19
  92. data/test/rubygems/test_gem_commands_signin_command.rb +1 -1
  93. data/test/rubygems/test_gem_commands_uninstall_command.rb +1 -1
  94. data/test/rubygems/test_gem_commands_yank_command.rb +1 -1
  95. data/test/rubygems/test_gem_install_update_options.rb +2 -2
  96. data/test/rubygems/test_gem_request.rb +10 -4
  97. data/test/rubygems/test_gem_resolver.rb +7 -7
  98. data/test/rubygems/test_gem_specification.rb +11 -0
  99. metadata +21 -3
@@ -56,7 +56,6 @@ module Bundler
56
56
  @ref = ref
57
57
  @revision = revision
58
58
  @git = git
59
- raise GitNotInstalledError.new if allow? && !Bundler.git_present?
60
59
  end
61
60
 
62
61
  def revision
@@ -208,7 +207,11 @@ module Bundler
208
207
  end
209
208
 
210
209
  def allow?
211
- @git ? @git.allow_git_ops? : true
210
+ allowed = @git ? @git.allow_git_ops? : true
211
+
212
+ raise GitNotInstalledError.new if allowed && !Bundler.git_present?
213
+
214
+ allowed
212
215
  end
213
216
 
214
217
  def with_path(&blk)
@@ -162,7 +162,7 @@ module Bundler
162
162
  begin
163
163
  s = Bundler.rubygems.spec_from_gem(path, Bundler.settings["trust-policy"])
164
164
  spec.__swap__(s)
165
- rescue StandardError
165
+ rescue Gem::Package::FormatError
166
166
  Bundler.rm_rf(path)
167
167
  raise
168
168
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "tsort"
3
+ require_relative "vendored_tsort"
4
4
 
5
5
  module Bundler
6
6
  class SpecSet
@@ -14,7 +14,10 @@ gem "rake-compiler"
14
14
 
15
15
  gem "<%= config[:test] %>", "~> <%= config[:test_framework_version] %>"
16
16
  <%- end -%>
17
- <%- if config[:rubocop] -%>
17
+ <%- if config[:linter] == "rubocop" -%>
18
18
 
19
- gem "rubocop", "~> <%= config[:rubocop_version] %>"
19
+ gem "rubocop", "~> <%= config[:linter_version] %>"
20
+ <%- elsif config[:linter] == "standard" -%>
21
+
22
+ gem "standard", "~> <%= config[:linter_version] %>"
20
23
  <%- end -%>
@@ -18,12 +18,16 @@ require "rspec/core/rake_task"
18
18
  RSpec::Core::RakeTask.new(:spec)
19
19
 
20
20
  <% end -%>
21
- <% if config[:rubocop] -%>
21
+ <% if config[:linter] == "rubocop" -%>
22
22
  <% default_task_names << :rubocop -%>
23
23
  require "rubocop/rake_task"
24
24
 
25
25
  RuboCop::RakeTask.new
26
26
 
27
+ <% elsif config[:linter] == "standard" -%>
28
+ <% default_task_names << :standard -%>
29
+ require "standard/rake"
30
+
27
31
  <% end -%>
28
32
  <% if config[:ext] -%>
29
33
  <% default_task_names.unshift(:clobber, :compile) -%>
@@ -3,16 +3,16 @@
3
3
  require_relative "lib/<%=config[:namespaced_path]%>/version"
4
4
 
5
5
  Gem::Specification.new do |spec|
6
- spec.name = <%= config[:name].inspect %>
7
- spec.version = <%= config[:constant_name] %>::VERSION
8
- spec.authors = [<%= config[:author].inspect %>]
9
- spec.email = [<%= config[:email].inspect %>]
10
-
11
- spec.summary = "TODO: Write a short summary, because RubyGems requires one."
12
- spec.description = "TODO: Write a longer description or delete this line."
13
- spec.homepage = "TODO: Put your gem's website or public repo URL here."
6
+ spec.name = <%= config[:name].inspect %>
7
+ spec.version = <%= config[:constant_name] %>::VERSION
8
+ spec.authors = [<%= config[:author].inspect %>]
9
+ spec.email = [<%= config[:email].inspect %>]
10
+
11
+ spec.summary = "TODO: Write a short summary, because RubyGems requires one."
12
+ spec.description = "TODO: Write a longer description or delete this line."
13
+ spec.homepage = "TODO: Put your gem's website or public repo URL here."
14
14
  <%- if config[:mit] -%>
15
- spec.license = "MIT"
15
+ spec.license = "MIT"
16
16
  <%- end -%>
17
17
  spec.required_ruby_version = ">= <%= config[:required_ruby_version] %>"
18
18
 
@@ -29,11 +29,11 @@ Gem::Specification.new do |spec|
29
29
  (f == __FILE__) || f.match(%r{\A(?:(?:test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
30
30
  end
31
31
  end
32
- spec.bindir = "exe"
33
- spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
32
+ spec.bindir = "exe"
33
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
34
34
  spec.require_paths = ["lib"]
35
35
  <%- if config[:ext] -%>
36
- spec.extensions = ["ext/<%= config[:underscored_name] %>/extconf.rb"]
36
+ spec.extensions = ["ext/<%= config[:underscored_name] %>/extconf.rb"]
37
37
  <%- end -%>
38
38
 
39
39
  # Uncomment to register a new dependency of your gem
@@ -0,0 +1,4 @@
1
+ # For available configuration options, see:
2
+ # https://github.com/testdouble/standard
3
+
4
+ default_ignores: false
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'tsort'
3
+ require_relative '../../../../vendored_tsort'
4
4
 
5
5
  require_relative 'dependency_graph/log'
6
6
  require_relative 'dependency_graph/vertex'
@@ -17,7 +17,7 @@ module Bundler::Molinillo
17
17
  vertices.values.each { |v| yield v }
18
18
  end
19
19
 
20
- include TSort
20
+ include Bundler::TSort
21
21
 
22
22
  # @!visibility private
23
23
  alias tsort_each_node each
@@ -0,0 +1,22 @@
1
+ Copyright (C) 1993-2013 Yukihiro Matsumoto. All rights reserved.
2
+
3
+ Redistribution and use in source and binary forms, with or without
4
+ modification, are permitted provided that the following conditions
5
+ are met:
6
+ 1. Redistributions of source code must retain the above copyright
7
+ notice, this list of conditions and the following disclaimer.
8
+ 2. Redistributions in binary form must reproduce the above copyright
9
+ notice, this list of conditions and the following disclaimer in the
10
+ documentation and/or other materials provided with the distribution.
11
+
12
+ THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
13
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
14
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
15
+ ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
16
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
17
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
18
+ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
19
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
20
+ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
21
+ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
22
+ SUCH DAMAGE.
@@ -0,0 +1,453 @@
1
+ # frozen_string_literal: true
2
+
3
+ #--
4
+ # tsort.rb - provides a module for topological sorting and strongly connected components.
5
+ #++
6
+ #
7
+
8
+ #
9
+ # TSort implements topological sorting using Tarjan's algorithm for
10
+ # strongly connected components.
11
+ #
12
+ # TSort is designed to be able to be used with any object which can be
13
+ # interpreted as a directed graph.
14
+ #
15
+ # TSort requires two methods to interpret an object as a graph,
16
+ # tsort_each_node and tsort_each_child.
17
+ #
18
+ # * tsort_each_node is used to iterate for all nodes over a graph.
19
+ # * tsort_each_child is used to iterate for child nodes of a given node.
20
+ #
21
+ # The equality of nodes are defined by eql? and hash since
22
+ # TSort uses Hash internally.
23
+ #
24
+ # == A Simple Example
25
+ #
26
+ # The following example demonstrates how to mix the TSort module into an
27
+ # existing class (in this case, Hash). Here, we're treating each key in
28
+ # the hash as a node in the graph, and so we simply alias the required
29
+ # #tsort_each_node method to Hash's #each_key method. For each key in the
30
+ # hash, the associated value is an array of the node's child nodes. This
31
+ # choice in turn leads to our implementation of the required #tsort_each_child
32
+ # method, which fetches the array of child nodes and then iterates over that
33
+ # array using the user-supplied block.
34
+ #
35
+ # require 'tsort'
36
+ #
37
+ # class Hash
38
+ # include TSort
39
+ # alias tsort_each_node each_key
40
+ # def tsort_each_child(node, &block)
41
+ # fetch(node).each(&block)
42
+ # end
43
+ # end
44
+ #
45
+ # {1=>[2, 3], 2=>[3], 3=>[], 4=>[]}.tsort
46
+ # #=> [3, 2, 1, 4]
47
+ #
48
+ # {1=>[2], 2=>[3, 4], 3=>[2], 4=>[]}.strongly_connected_components
49
+ # #=> [[4], [2, 3], [1]]
50
+ #
51
+ # == A More Realistic Example
52
+ #
53
+ # A very simple `make' like tool can be implemented as follows:
54
+ #
55
+ # require 'tsort'
56
+ #
57
+ # class Make
58
+ # def initialize
59
+ # @dep = {}
60
+ # @dep.default = []
61
+ # end
62
+ #
63
+ # def rule(outputs, inputs=[], &block)
64
+ # triple = [outputs, inputs, block]
65
+ # outputs.each {|f| @dep[f] = [triple]}
66
+ # @dep[triple] = inputs
67
+ # end
68
+ #
69
+ # def build(target)
70
+ # each_strongly_connected_component_from(target) {|ns|
71
+ # if ns.length != 1
72
+ # fs = ns.delete_if {|n| Array === n}
73
+ # raise TSort::Cyclic.new("cyclic dependencies: #{fs.join ', '}")
74
+ # end
75
+ # n = ns.first
76
+ # if Array === n
77
+ # outputs, inputs, block = n
78
+ # inputs_time = inputs.map {|f| File.mtime f}.max
79
+ # begin
80
+ # outputs_time = outputs.map {|f| File.mtime f}.min
81
+ # rescue Errno::ENOENT
82
+ # outputs_time = nil
83
+ # end
84
+ # if outputs_time == nil ||
85
+ # inputs_time != nil && outputs_time <= inputs_time
86
+ # sleep 1 if inputs_time != nil && inputs_time.to_i == Time.now.to_i
87
+ # block.call
88
+ # end
89
+ # end
90
+ # }
91
+ # end
92
+ #
93
+ # def tsort_each_child(node, &block)
94
+ # @dep[node].each(&block)
95
+ # end
96
+ # include TSort
97
+ # end
98
+ #
99
+ # def command(arg)
100
+ # print arg, "\n"
101
+ # system arg
102
+ # end
103
+ #
104
+ # m = Make.new
105
+ # m.rule(%w[t1]) { command 'date > t1' }
106
+ # m.rule(%w[t2]) { command 'date > t2' }
107
+ # m.rule(%w[t3]) { command 'date > t3' }
108
+ # m.rule(%w[t4], %w[t1 t3]) { command 'cat t1 t3 > t4' }
109
+ # m.rule(%w[t5], %w[t4 t2]) { command 'cat t4 t2 > t5' }
110
+ # m.build('t5')
111
+ #
112
+ # == Bugs
113
+ #
114
+ # * 'tsort.rb' is wrong name because this library uses
115
+ # Tarjan's algorithm for strongly connected components.
116
+ # Although 'strongly_connected_components.rb' is correct but too long.
117
+ #
118
+ # == References
119
+ #
120
+ # R. E. Tarjan, "Depth First Search and Linear Graph Algorithms",
121
+ # <em>SIAM Journal on Computing</em>, Vol. 1, No. 2, pp. 146-160, June 1972.
122
+ #
123
+ module Bundler
124
+ module TSort
125
+ class Cyclic < StandardError
126
+ end
127
+
128
+ # Returns a topologically sorted array of nodes.
129
+ # The array is sorted from children to parents, i.e.
130
+ # the first element has no child and the last node has no parent.
131
+ #
132
+ # If there is a cycle, TSort::Cyclic is raised.
133
+ #
134
+ # class G
135
+ # include TSort
136
+ # def initialize(g)
137
+ # @g = g
138
+ # end
139
+ # def tsort_each_child(n, &b) @g[n].each(&b) end
140
+ # def tsort_each_node(&b) @g.each_key(&b) end
141
+ # end
142
+ #
143
+ # graph = G.new({1=>[2, 3], 2=>[4], 3=>[2, 4], 4=>[]})
144
+ # p graph.tsort #=> [4, 2, 3, 1]
145
+ #
146
+ # graph = G.new({1=>[2], 2=>[3, 4], 3=>[2], 4=>[]})
147
+ # p graph.tsort # raises TSort::Cyclic
148
+ #
149
+ def tsort
150
+ each_node = method(:tsort_each_node)
151
+ each_child = method(:tsort_each_child)
152
+ TSort.tsort(each_node, each_child)
153
+ end
154
+
155
+ # Returns a topologically sorted array of nodes.
156
+ # The array is sorted from children to parents, i.e.
157
+ # the first element has no child and the last node has no parent.
158
+ #
159
+ # The graph is represented by _each_node_ and _each_child_.
160
+ # _each_node_ should have +call+ method which yields for each node in the graph.
161
+ # _each_child_ should have +call+ method which takes a node argument and yields for each child node.
162
+ #
163
+ # If there is a cycle, TSort::Cyclic is raised.
164
+ #
165
+ # g = {1=>[2, 3], 2=>[4], 3=>[2, 4], 4=>[]}
166
+ # each_node = lambda {|&b| g.each_key(&b) }
167
+ # each_child = lambda {|n, &b| g[n].each(&b) }
168
+ # p TSort.tsort(each_node, each_child) #=> [4, 2, 3, 1]
169
+ #
170
+ # g = {1=>[2], 2=>[3, 4], 3=>[2], 4=>[]}
171
+ # each_node = lambda {|&b| g.each_key(&b) }
172
+ # each_child = lambda {|n, &b| g[n].each(&b) }
173
+ # p TSort.tsort(each_node, each_child) # raises TSort::Cyclic
174
+ #
175
+ def TSort.tsort(each_node, each_child)
176
+ TSort.tsort_each(each_node, each_child).to_a
177
+ end
178
+
179
+ # The iterator version of the #tsort method.
180
+ # <tt><em>obj</em>.tsort_each</tt> is similar to <tt><em>obj</em>.tsort.each</tt>, but
181
+ # modification of _obj_ during the iteration may lead to unexpected results.
182
+ #
183
+ # #tsort_each returns +nil+.
184
+ # If there is a cycle, TSort::Cyclic is raised.
185
+ #
186
+ # class G
187
+ # include TSort
188
+ # def initialize(g)
189
+ # @g = g
190
+ # end
191
+ # def tsort_each_child(n, &b) @g[n].each(&b) end
192
+ # def tsort_each_node(&b) @g.each_key(&b) end
193
+ # end
194
+ #
195
+ # graph = G.new({1=>[2, 3], 2=>[4], 3=>[2, 4], 4=>[]})
196
+ # graph.tsort_each {|n| p n }
197
+ # #=> 4
198
+ # # 2
199
+ # # 3
200
+ # # 1
201
+ #
202
+ def tsort_each(&block) # :yields: node
203
+ each_node = method(:tsort_each_node)
204
+ each_child = method(:tsort_each_child)
205
+ TSort.tsort_each(each_node, each_child, &block)
206
+ end
207
+
208
+ # The iterator version of the TSort.tsort method.
209
+ #
210
+ # The graph is represented by _each_node_ and _each_child_.
211
+ # _each_node_ should have +call+ method which yields for each node in the graph.
212
+ # _each_child_ should have +call+ method which takes a node argument and yields for each child node.
213
+ #
214
+ # g = {1=>[2, 3], 2=>[4], 3=>[2, 4], 4=>[]}
215
+ # each_node = lambda {|&b| g.each_key(&b) }
216
+ # each_child = lambda {|n, &b| g[n].each(&b) }
217
+ # TSort.tsort_each(each_node, each_child) {|n| p n }
218
+ # #=> 4
219
+ # # 2
220
+ # # 3
221
+ # # 1
222
+ #
223
+ def TSort.tsort_each(each_node, each_child) # :yields: node
224
+ return to_enum(__method__, each_node, each_child) unless block_given?
225
+
226
+ TSort.each_strongly_connected_component(each_node, each_child) {|component|
227
+ if component.size == 1
228
+ yield component.first
229
+ else
230
+ raise Cyclic.new("topological sort failed: #{component.inspect}")
231
+ end
232
+ }
233
+ end
234
+
235
+ # Returns strongly connected components as an array of arrays of nodes.
236
+ # The array is sorted from children to parents.
237
+ # Each elements of the array represents a strongly connected component.
238
+ #
239
+ # class G
240
+ # include TSort
241
+ # def initialize(g)
242
+ # @g = g
243
+ # end
244
+ # def tsort_each_child(n, &b) @g[n].each(&b) end
245
+ # def tsort_each_node(&b) @g.each_key(&b) end
246
+ # end
247
+ #
248
+ # graph = G.new({1=>[2, 3], 2=>[4], 3=>[2, 4], 4=>[]})
249
+ # p graph.strongly_connected_components #=> [[4], [2], [3], [1]]
250
+ #
251
+ # graph = G.new({1=>[2], 2=>[3, 4], 3=>[2], 4=>[]})
252
+ # p graph.strongly_connected_components #=> [[4], [2, 3], [1]]
253
+ #
254
+ def strongly_connected_components
255
+ each_node = method(:tsort_each_node)
256
+ each_child = method(:tsort_each_child)
257
+ TSort.strongly_connected_components(each_node, each_child)
258
+ end
259
+
260
+ # Returns strongly connected components as an array of arrays of nodes.
261
+ # The array is sorted from children to parents.
262
+ # Each elements of the array represents a strongly connected component.
263
+ #
264
+ # The graph is represented by _each_node_ and _each_child_.
265
+ # _each_node_ should have +call+ method which yields for each node in the graph.
266
+ # _each_child_ should have +call+ method which takes a node argument and yields for each child node.
267
+ #
268
+ # g = {1=>[2, 3], 2=>[4], 3=>[2, 4], 4=>[]}
269
+ # each_node = lambda {|&b| g.each_key(&b) }
270
+ # each_child = lambda {|n, &b| g[n].each(&b) }
271
+ # p TSort.strongly_connected_components(each_node, each_child)
272
+ # #=> [[4], [2], [3], [1]]
273
+ #
274
+ # g = {1=>[2], 2=>[3, 4], 3=>[2], 4=>[]}
275
+ # each_node = lambda {|&b| g.each_key(&b) }
276
+ # each_child = lambda {|n, &b| g[n].each(&b) }
277
+ # p TSort.strongly_connected_components(each_node, each_child)
278
+ # #=> [[4], [2, 3], [1]]
279
+ #
280
+ def TSort.strongly_connected_components(each_node, each_child)
281
+ TSort.each_strongly_connected_component(each_node, each_child).to_a
282
+ end
283
+
284
+ # The iterator version of the #strongly_connected_components method.
285
+ # <tt><em>obj</em>.each_strongly_connected_component</tt> is similar to
286
+ # <tt><em>obj</em>.strongly_connected_components.each</tt>, but
287
+ # modification of _obj_ during the iteration may lead to unexpected results.
288
+ #
289
+ # #each_strongly_connected_component returns +nil+.
290
+ #
291
+ # class G
292
+ # include TSort
293
+ # def initialize(g)
294
+ # @g = g
295
+ # end
296
+ # def tsort_each_child(n, &b) @g[n].each(&b) end
297
+ # def tsort_each_node(&b) @g.each_key(&b) end
298
+ # end
299
+ #
300
+ # graph = G.new({1=>[2, 3], 2=>[4], 3=>[2, 4], 4=>[]})
301
+ # graph.each_strongly_connected_component {|scc| p scc }
302
+ # #=> [4]
303
+ # # [2]
304
+ # # [3]
305
+ # # [1]
306
+ #
307
+ # graph = G.new({1=>[2], 2=>[3, 4], 3=>[2], 4=>[]})
308
+ # graph.each_strongly_connected_component {|scc| p scc }
309
+ # #=> [4]
310
+ # # [2, 3]
311
+ # # [1]
312
+ #
313
+ def each_strongly_connected_component(&block) # :yields: nodes
314
+ each_node = method(:tsort_each_node)
315
+ each_child = method(:tsort_each_child)
316
+ TSort.each_strongly_connected_component(each_node, each_child, &block)
317
+ end
318
+
319
+ # The iterator version of the TSort.strongly_connected_components method.
320
+ #
321
+ # The graph is represented by _each_node_ and _each_child_.
322
+ # _each_node_ should have +call+ method which yields for each node in the graph.
323
+ # _each_child_ should have +call+ method which takes a node argument and yields for each child node.
324
+ #
325
+ # g = {1=>[2, 3], 2=>[4], 3=>[2, 4], 4=>[]}
326
+ # each_node = lambda {|&b| g.each_key(&b) }
327
+ # each_child = lambda {|n, &b| g[n].each(&b) }
328
+ # TSort.each_strongly_connected_component(each_node, each_child) {|scc| p scc }
329
+ # #=> [4]
330
+ # # [2]
331
+ # # [3]
332
+ # # [1]
333
+ #
334
+ # g = {1=>[2], 2=>[3, 4], 3=>[2], 4=>[]}
335
+ # each_node = lambda {|&b| g.each_key(&b) }
336
+ # each_child = lambda {|n, &b| g[n].each(&b) }
337
+ # TSort.each_strongly_connected_component(each_node, each_child) {|scc| p scc }
338
+ # #=> [4]
339
+ # # [2, 3]
340
+ # # [1]
341
+ #
342
+ def TSort.each_strongly_connected_component(each_node, each_child) # :yields: nodes
343
+ return to_enum(__method__, each_node, each_child) unless block_given?
344
+
345
+ id_map = {}
346
+ stack = []
347
+ each_node.call {|node|
348
+ unless id_map.include? node
349
+ TSort.each_strongly_connected_component_from(node, each_child, id_map, stack) {|c|
350
+ yield c
351
+ }
352
+ end
353
+ }
354
+ nil
355
+ end
356
+
357
+ # Iterates over strongly connected component in the subgraph reachable from
358
+ # _node_.
359
+ #
360
+ # Return value is unspecified.
361
+ #
362
+ # #each_strongly_connected_component_from doesn't call #tsort_each_node.
363
+ #
364
+ # class G
365
+ # include TSort
366
+ # def initialize(g)
367
+ # @g = g
368
+ # end
369
+ # def tsort_each_child(n, &b) @g[n].each(&b) end
370
+ # def tsort_each_node(&b) @g.each_key(&b) end
371
+ # end
372
+ #
373
+ # graph = G.new({1=>[2, 3], 2=>[4], 3=>[2, 4], 4=>[]})
374
+ # graph.each_strongly_connected_component_from(2) {|scc| p scc }
375
+ # #=> [4]
376
+ # # [2]
377
+ #
378
+ # graph = G.new({1=>[2], 2=>[3, 4], 3=>[2], 4=>[]})
379
+ # graph.each_strongly_connected_component_from(2) {|scc| p scc }
380
+ # #=> [4]
381
+ # # [2, 3]
382
+ #
383
+ def each_strongly_connected_component_from(node, id_map={}, stack=[], &block) # :yields: nodes
384
+ TSort.each_strongly_connected_component_from(node, method(:tsort_each_child), id_map, stack, &block)
385
+ end
386
+
387
+ # Iterates over strongly connected components in a graph.
388
+ # The graph is represented by _node_ and _each_child_.
389
+ #
390
+ # _node_ is the first node.
391
+ # _each_child_ should have +call+ method which takes a node argument
392
+ # and yields for each child node.
393
+ #
394
+ # Return value is unspecified.
395
+ #
396
+ # #TSort.each_strongly_connected_component_from is a class method and
397
+ # it doesn't need a class to represent a graph which includes TSort.
398
+ #
399
+ # graph = {1=>[2], 2=>[3, 4], 3=>[2], 4=>[]}
400
+ # each_child = lambda {|n, &b| graph[n].each(&b) }
401
+ # TSort.each_strongly_connected_component_from(1, each_child) {|scc|
402
+ # p scc
403
+ # }
404
+ # #=> [4]
405
+ # # [2, 3]
406
+ # # [1]
407
+ #
408
+ def TSort.each_strongly_connected_component_from(node, each_child, id_map={}, stack=[]) # :yields: nodes
409
+ return to_enum(__method__, node, each_child, id_map, stack) unless block_given?
410
+
411
+ minimum_id = node_id = id_map[node] = id_map.size
412
+ stack_length = stack.length
413
+ stack << node
414
+
415
+ each_child.call(node) {|child|
416
+ if id_map.include? child
417
+ child_id = id_map[child]
418
+ minimum_id = child_id if child_id && child_id < minimum_id
419
+ else
420
+ sub_minimum_id =
421
+ TSort.each_strongly_connected_component_from(child, each_child, id_map, stack) {|c|
422
+ yield c
423
+ }
424
+ minimum_id = sub_minimum_id if sub_minimum_id < minimum_id
425
+ end
426
+ }
427
+
428
+ if node_id == minimum_id
429
+ component = stack.slice!(stack_length .. -1)
430
+ component.each {|n| id_map[n] = nil}
431
+ yield component
432
+ end
433
+
434
+ minimum_id
435
+ end
436
+
437
+ # Should be implemented by a extended class.
438
+ #
439
+ # #tsort_each_node is used to iterate for all nodes over a graph.
440
+ #
441
+ def tsort_each_node # :yields: node
442
+ raise NotImplementedError.new
443
+ end
444
+
445
+ # Should be implemented by a extended class.
446
+ #
447
+ # #tsort_each_child is used to iterate for child nodes of _node_.
448
+ #
449
+ def tsort_each_child(node) # :yields: child
450
+ raise NotImplementedError.new
451
+ end
452
+ end
453
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bundler; end
4
+ require_relative "vendor/tsort/lib/tsort"
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: false
2
2
 
3
3
  module Bundler
4
- VERSION = "2.2.30".freeze
4
+ VERSION = "2.2.31".freeze
5
5
 
6
6
  def self.bundler_major_version
7
7
  @bundler_major_version ||= VERSION.split(".").first.to_i
@@ -5,7 +5,7 @@
5
5
  # See LICENSE.txt for permissions.
6
6
  #++
7
7
 
8
- require 'optparse'
8
+ require_relative 'optparse'
9
9
  require_relative 'requirement'
10
10
  require_relative 'user_interaction'
11
11
 
@@ -19,7 +19,7 @@ require_relative 'user_interaction'
19
19
  class Gem::Command
20
20
  include Gem::UserInteraction
21
21
 
22
- OptionParser.accept Symbol do |value|
22
+ Gem::OptionParser.accept Symbol do |value|
23
23
  value.to_sym
24
24
  end
25
25
 
@@ -344,7 +344,7 @@ class Gem::Command
344
344
  ##
345
345
  # Add a command-line option and handler to the command.
346
346
  #
347
- # See OptionParser#make_switch for an explanation of +opts+.
347
+ # See Gem::OptionParser#make_switch for an explanation of +opts+.
348
348
  #
349
349
  # +handler+ will be called with two values, the value of the argument and
350
350
  # the options hash.
@@ -540,7 +540,7 @@ class Gem::Command
540
540
  # command.
541
541
 
542
542
  def create_option_parser
543
- @parser = OptionParser.new
543
+ @parser = Gem::OptionParser.new
544
544
 
545
545
  add_parser_options
546
546