kuby-core 0.7.2 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (135) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +42 -0
  3. data/Gemfile +1 -0
  4. data/README.md +11 -1
  5. data/bin/kuby +4 -0
  6. data/kuby-core.gemspec +9 -4
  7. data/lib/kuby.rb +58 -19
  8. data/lib/kuby/basic_logger.rb +13 -0
  9. data/lib/kuby/cli_base.rb +81 -8
  10. data/lib/kuby/commands.rb +244 -0
  11. data/lib/kuby/definition.rb +1 -11
  12. data/lib/kuby/dev_setup.rb +255 -0
  13. data/lib/kuby/docker.rb +1 -0
  14. data/lib/kuby/docker/bundler_phase.rb +3 -3
  15. data/lib/kuby/docker/cli.rb +13 -1
  16. data/lib/kuby/docker/dev_spec.rb +131 -0
  17. data/lib/kuby/docker/dockerfile.rb +16 -1
  18. data/lib/kuby/docker/layer.rb +4 -4
  19. data/lib/kuby/docker/layer_stack.rb +4 -0
  20. data/lib/kuby/docker/local_tags.rb +4 -0
  21. data/lib/kuby/docker/metadata.rb +18 -38
  22. data/lib/kuby/docker/package_phase.rb +2 -2
  23. data/lib/kuby/docker/setup_phase.rb +3 -2
  24. data/lib/kuby/docker/spec.rb +42 -16
  25. data/lib/kuby/docker/timestamp_tag.rb +6 -0
  26. data/lib/kuby/environment.rb +15 -2
  27. data/lib/kuby/kubernetes.rb +9 -11
  28. data/lib/kuby/kubernetes/deploy_task.rb +4 -1
  29. data/lib/kuby/kubernetes/deployer.rb +70 -15
  30. data/lib/kuby/kubernetes/{minikube_provider.rb → docker_desktop_provider.rb} +8 -4
  31. data/lib/kuby/kubernetes/provider.rb +12 -8
  32. data/lib/kuby/kubernetes/spec.rb +30 -29
  33. data/lib/kuby/plugin.rb +59 -0
  34. data/lib/kuby/plugin_registry.rb +27 -0
  35. data/lib/kuby/plugins.rb +6 -0
  36. data/lib/kuby/plugins/nginx_ingress.rb +71 -0
  37. data/lib/kuby/plugins/rails_app.rb +18 -0
  38. data/lib/kuby/plugins/rails_app/asset_copy_task.rb +117 -0
  39. data/lib/kuby/plugins/rails_app/assets.rb +347 -0
  40. data/lib/kuby/plugins/rails_app/database.rb +74 -0
  41. data/lib/kuby/{kubernetes/plugins → plugins}/rails_app/generators/kuby.rb +14 -16
  42. data/lib/kuby/plugins/rails_app/mysql.rb +152 -0
  43. data/lib/kuby/plugins/rails_app/plugin.rb +593 -0
  44. data/lib/kuby/plugins/rails_app/postgres.rb +143 -0
  45. data/lib/kuby/plugins/rails_app/rewrite_db_config.rb +11 -0
  46. data/lib/kuby/plugins/rails_app/sqlite.rb +32 -0
  47. data/lib/kuby/plugins/rails_app/tasks.rake +36 -0
  48. data/lib/kuby/rails_commands.rb +89 -0
  49. data/lib/kuby/railtie.rb +0 -4
  50. data/lib/kuby/tasks.rb +85 -31
  51. data/lib/kuby/version.rb +1 -1
  52. data/spec/docker/metadata_spec.rb +84 -0
  53. data/spec/docker/spec_spec.rb +266 -0
  54. data/spec/docker/timestamp_tag_spec.rb +54 -4
  55. data/spec/dummy/Gemfile +54 -0
  56. data/spec/dummy/Gemfile.lock +223 -0
  57. data/spec/dummy/README.md +24 -0
  58. data/spec/dummy/Rakefile +6 -0
  59. data/spec/dummy/app/assets/config/manifest.js +2 -0
  60. data/spec/dummy/app/assets/stylesheets/application.css +15 -0
  61. data/spec/dummy/app/channels/application_cable/channel.rb +4 -0
  62. data/spec/dummy/app/channels/application_cable/connection.rb +4 -0
  63. data/spec/dummy/app/controllers/application_controller.rb +2 -0
  64. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  65. data/spec/dummy/app/javascript/channels/consumer.js +6 -0
  66. data/spec/dummy/app/javascript/channels/index.js +5 -0
  67. data/spec/dummy/app/javascript/packs/application.js +17 -0
  68. data/spec/dummy/app/jobs/application_job.rb +7 -0
  69. data/spec/dummy/app/mailers/application_mailer.rb +4 -0
  70. data/spec/dummy/app/models/application_record.rb +3 -0
  71. data/spec/dummy/app/views/layouts/application.html.erb +15 -0
  72. data/spec/dummy/app/views/layouts/mailer.html.erb +13 -0
  73. data/spec/dummy/app/views/layouts/mailer.text.erb +1 -0
  74. data/spec/dummy/bin/bundle +114 -0
  75. data/spec/dummy/bin/rails +9 -0
  76. data/spec/dummy/bin/rake +9 -0
  77. data/spec/dummy/bin/setup +36 -0
  78. data/spec/dummy/bin/spring +17 -0
  79. data/spec/dummy/bin/yarn +11 -0
  80. data/spec/dummy/config.ru +5 -0
  81. data/spec/dummy/config/application.rb +19 -0
  82. data/spec/dummy/config/boot.rb +4 -0
  83. data/spec/dummy/config/cable.yml +10 -0
  84. data/spec/dummy/config/credentials.yml.enc +1 -0
  85. data/spec/dummy/config/database.yml +25 -0
  86. data/spec/dummy/config/environment.rb +5 -0
  87. data/spec/dummy/config/environments/development.rb +62 -0
  88. data/spec/dummy/config/environments/production.rb +112 -0
  89. data/spec/dummy/config/environments/test.rb +49 -0
  90. data/spec/dummy/config/initializers/application_controller_renderer.rb +8 -0
  91. data/spec/dummy/config/initializers/assets.rb +14 -0
  92. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  93. data/spec/dummy/config/initializers/content_security_policy.rb +30 -0
  94. data/spec/dummy/config/initializers/cookies_serializer.rb +5 -0
  95. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  96. data/spec/dummy/config/initializers/inflections.rb +16 -0
  97. data/spec/dummy/config/initializers/mime_types.rb +4 -0
  98. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  99. data/spec/dummy/config/locales/en.yml +33 -0
  100. data/spec/dummy/config/master.key +1 -0
  101. data/spec/dummy/config/puma.rb +38 -0
  102. data/spec/dummy/config/routes.rb +3 -0
  103. data/spec/dummy/config/spring.rb +6 -0
  104. data/spec/dummy/config/storage.yml +34 -0
  105. data/spec/dummy/db/seeds.rb +7 -0
  106. data/spec/dummy/package.json +11 -0
  107. data/spec/dummy/public/404.html +67 -0
  108. data/spec/dummy/public/422.html +67 -0
  109. data/spec/dummy/public/500.html +66 -0
  110. data/spec/dummy/public/apple-touch-icon-precomposed.png +0 -0
  111. data/spec/dummy/public/apple-touch-icon.png +0 -0
  112. data/spec/dummy/public/favicon.ico +0 -0
  113. data/spec/dummy/public/robots.txt +1 -0
  114. data/spec/dummy/test/application_system_test_case.rb +5 -0
  115. data/spec/dummy/test/channels/application_cable/connection_test.rb +11 -0
  116. data/spec/dummy/test/test_helper.rb +13 -0
  117. data/spec/dummy/tmp/cache/bootsnap-load-path-cache +0 -0
  118. data/spec/spec_helper.rb +77 -2
  119. data/spec/support/docker/fake_cli.rb +54 -0
  120. data/spec/support/docker/remote/fake_client.rb +16 -0
  121. data/spec/trailing_hash_spec.rb +23 -0
  122. metadata +139 -30
  123. data/lib/ext/krane/kubernetes_resource.rb +0 -16
  124. data/lib/kuby/kubernetes/plugin.rb +0 -55
  125. data/lib/kuby/kubernetes/plugins.rb +0 -8
  126. data/lib/kuby/kubernetes/plugins/nginx_ingress.rb +0 -73
  127. data/lib/kuby/kubernetes/plugins/rails_app.rb +0 -16
  128. data/lib/kuby/kubernetes/plugins/rails_app/database.rb +0 -79
  129. data/lib/kuby/kubernetes/plugins/rails_app/mysql.rb +0 -154
  130. data/lib/kuby/kubernetes/plugins/rails_app/plugin.rb +0 -379
  131. data/lib/kuby/kubernetes/plugins/rails_app/postgres.rb +0 -142
  132. data/lib/kuby/kubernetes/plugins/rails_app/rewrite_db_config.rb +0 -13
  133. data/lib/kuby/kubernetes/plugins/rails_app/sqlite.rb +0 -30
  134. data/lib/kuby/kubernetes/plugins/rails_app/tasks.rake +0 -28
  135. data/lib/kuby/tasks/kuby.rake +0 -70
@@ -0,0 +1,223 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ actioncable (6.0.3.2)
5
+ actionpack (= 6.0.3.2)
6
+ nio4r (~> 2.0)
7
+ websocket-driver (>= 0.6.1)
8
+ actionmailbox (6.0.3.2)
9
+ actionpack (= 6.0.3.2)
10
+ activejob (= 6.0.3.2)
11
+ activerecord (= 6.0.3.2)
12
+ activestorage (= 6.0.3.2)
13
+ activesupport (= 6.0.3.2)
14
+ mail (>= 2.7.1)
15
+ actionmailer (6.0.3.2)
16
+ actionpack (= 6.0.3.2)
17
+ actionview (= 6.0.3.2)
18
+ activejob (= 6.0.3.2)
19
+ mail (~> 2.5, >= 2.5.4)
20
+ rails-dom-testing (~> 2.0)
21
+ actionpack (6.0.3.2)
22
+ actionview (= 6.0.3.2)
23
+ activesupport (= 6.0.3.2)
24
+ rack (~> 2.0, >= 2.0.8)
25
+ rack-test (>= 0.6.3)
26
+ rails-dom-testing (~> 2.0)
27
+ rails-html-sanitizer (~> 1.0, >= 1.2.0)
28
+ actiontext (6.0.3.2)
29
+ actionpack (= 6.0.3.2)
30
+ activerecord (= 6.0.3.2)
31
+ activestorage (= 6.0.3.2)
32
+ activesupport (= 6.0.3.2)
33
+ nokogiri (>= 1.8.5)
34
+ actionview (6.0.3.2)
35
+ activesupport (= 6.0.3.2)
36
+ builder (~> 3.1)
37
+ erubi (~> 1.4)
38
+ rails-dom-testing (~> 2.0)
39
+ rails-html-sanitizer (~> 1.1, >= 1.2.0)
40
+ activejob (6.0.3.2)
41
+ activesupport (= 6.0.3.2)
42
+ globalid (>= 0.3.6)
43
+ activemodel (6.0.3.2)
44
+ activesupport (= 6.0.3.2)
45
+ activerecord (6.0.3.2)
46
+ activemodel (= 6.0.3.2)
47
+ activesupport (= 6.0.3.2)
48
+ activestorage (6.0.3.2)
49
+ actionpack (= 6.0.3.2)
50
+ activejob (= 6.0.3.2)
51
+ activerecord (= 6.0.3.2)
52
+ marcel (~> 0.3.1)
53
+ activesupport (6.0.3.2)
54
+ concurrent-ruby (~> 1.0, >= 1.0.2)
55
+ i18n (>= 0.7, < 2)
56
+ minitest (~> 5.1)
57
+ tzinfo (~> 1.1)
58
+ zeitwerk (~> 2.2, >= 2.2.2)
59
+ addressable (2.7.0)
60
+ public_suffix (>= 2.0.2, < 5.0)
61
+ bindex (0.8.1)
62
+ bootsnap (1.4.8)
63
+ msgpack (~> 1.0)
64
+ builder (3.2.4)
65
+ byebug (11.1.3)
66
+ capybara (3.33.0)
67
+ addressable
68
+ mini_mime (>= 0.1.3)
69
+ nokogiri (~> 1.8)
70
+ rack (>= 1.6.0)
71
+ rack-test (>= 0.6.3)
72
+ regexp_parser (~> 1.5)
73
+ xpath (~> 3.2)
74
+ childprocess (3.0.0)
75
+ concurrent-ruby (1.1.7)
76
+ crass (1.0.6)
77
+ erubi (1.9.0)
78
+ ffi (1.13.1)
79
+ globalid (0.4.2)
80
+ activesupport (>= 4.2.0)
81
+ i18n (1.8.5)
82
+ concurrent-ruby (~> 1.0)
83
+ jbuilder (2.10.0)
84
+ activesupport (>= 5.0.0)
85
+ listen (3.2.1)
86
+ rb-fsevent (~> 0.10, >= 0.10.3)
87
+ rb-inotify (~> 0.9, >= 0.9.10)
88
+ loofah (2.7.0)
89
+ crass (~> 1.0.2)
90
+ nokogiri (>= 1.5.9)
91
+ mail (2.7.1)
92
+ mini_mime (>= 0.1.1)
93
+ marcel (0.3.3)
94
+ mimemagic (~> 0.3.2)
95
+ method_source (1.0.0)
96
+ mimemagic (0.3.5)
97
+ mini_mime (1.0.2)
98
+ mini_portile2 (2.4.0)
99
+ minitest (5.14.1)
100
+ msgpack (1.3.3)
101
+ nio4r (2.5.2)
102
+ nokogiri (1.10.10)
103
+ mini_portile2 (~> 2.4.0)
104
+ public_suffix (4.0.5)
105
+ puma (4.3.5)
106
+ nio4r (~> 2.0)
107
+ rack (2.2.3)
108
+ rack-proxy (0.6.5)
109
+ rack
110
+ rack-test (1.1.0)
111
+ rack (>= 1.0, < 3)
112
+ rails (6.0.3.2)
113
+ actioncable (= 6.0.3.2)
114
+ actionmailbox (= 6.0.3.2)
115
+ actionmailer (= 6.0.3.2)
116
+ actionpack (= 6.0.3.2)
117
+ actiontext (= 6.0.3.2)
118
+ actionview (= 6.0.3.2)
119
+ activejob (= 6.0.3.2)
120
+ activemodel (= 6.0.3.2)
121
+ activerecord (= 6.0.3.2)
122
+ activestorage (= 6.0.3.2)
123
+ activesupport (= 6.0.3.2)
124
+ bundler (>= 1.3.0)
125
+ railties (= 6.0.3.2)
126
+ sprockets-rails (>= 2.0.0)
127
+ rails-dom-testing (2.0.3)
128
+ activesupport (>= 4.2.0)
129
+ nokogiri (>= 1.6)
130
+ rails-html-sanitizer (1.3.0)
131
+ loofah (~> 2.3)
132
+ railties (6.0.3.2)
133
+ actionpack (= 6.0.3.2)
134
+ activesupport (= 6.0.3.2)
135
+ method_source
136
+ rake (>= 0.8.7)
137
+ thor (>= 0.20.3, < 2.0)
138
+ rake (13.0.1)
139
+ rb-fsevent (0.10.4)
140
+ rb-inotify (0.10.1)
141
+ ffi (~> 1.0)
142
+ regexp_parser (1.7.1)
143
+ rubyzip (2.3.0)
144
+ sass-rails (6.0.0)
145
+ sassc-rails (~> 2.1, >= 2.1.1)
146
+ sassc (2.4.0)
147
+ ffi (~> 1.9)
148
+ sassc-rails (2.1.2)
149
+ railties (>= 4.0.0)
150
+ sassc (>= 2.0)
151
+ sprockets (> 3.0)
152
+ sprockets-rails
153
+ tilt
154
+ selenium-webdriver (3.142.7)
155
+ childprocess (>= 0.5, < 4.0)
156
+ rubyzip (>= 1.2.2)
157
+ spring (2.1.1)
158
+ spring-watcher-listen (2.0.1)
159
+ listen (>= 2.7, < 4.0)
160
+ spring (>= 1.2, < 3.0)
161
+ sprockets (4.0.2)
162
+ concurrent-ruby (~> 1.0)
163
+ rack (> 1, < 3)
164
+ sprockets-rails (3.2.1)
165
+ actionpack (>= 4.0)
166
+ activesupport (>= 4.0)
167
+ sprockets (>= 3.0.0)
168
+ sqlite3 (1.4.2)
169
+ thor (1.0.1)
170
+ thread_safe (0.3.6)
171
+ tilt (2.0.10)
172
+ turbolinks (5.2.1)
173
+ turbolinks-source (~> 5.2)
174
+ turbolinks-source (5.2.0)
175
+ tzinfo (1.2.7)
176
+ thread_safe (~> 0.1)
177
+ web-console (4.0.4)
178
+ actionview (>= 6.0.0)
179
+ activemodel (>= 6.0.0)
180
+ bindex (>= 0.4.0)
181
+ railties (>= 6.0.0)
182
+ webdrivers (4.4.1)
183
+ nokogiri (~> 1.6)
184
+ rubyzip (>= 1.3.0)
185
+ selenium-webdriver (>= 3.0, < 4.0)
186
+ webpacker (4.3.0)
187
+ activesupport (>= 4.2)
188
+ rack-proxy (>= 0.6.1)
189
+ railties (>= 4.2)
190
+ websocket-driver (0.7.3)
191
+ websocket-extensions (>= 0.1.0)
192
+ websocket-extensions (0.1.5)
193
+ xpath (3.2.0)
194
+ nokogiri (~> 1.8)
195
+ zeitwerk (2.4.0)
196
+
197
+ PLATFORMS
198
+ ruby
199
+
200
+ DEPENDENCIES
201
+ bootsnap (>= 1.4.2)
202
+ byebug
203
+ capybara (>= 2.15)
204
+ jbuilder (~> 2.7)
205
+ listen (~> 3.2)
206
+ puma (~> 4.1)
207
+ rails (~> 6.0.3, >= 6.0.3.2)
208
+ sass-rails (>= 6)
209
+ selenium-webdriver
210
+ spring
211
+ spring-watcher-listen (~> 2.0.0)
212
+ sqlite3 (~> 1.4)
213
+ turbolinks (~> 5)
214
+ tzinfo-data
215
+ web-console (>= 3.3.0)
216
+ webdrivers
217
+ webpacker (~> 4.0)
218
+
219
+ RUBY VERSION
220
+ ruby 2.5.8p224
221
+
222
+ BUNDLED WITH
223
+ 2.1.4
@@ -0,0 +1,24 @@
1
+ # README
2
+
3
+ This README would normally document whatever steps are necessary to get the
4
+ application up and running.
5
+
6
+ Things you may want to cover:
7
+
8
+ * Ruby version
9
+
10
+ * System dependencies
11
+
12
+ * Configuration
13
+
14
+ * Database creation
15
+
16
+ * Database initialization
17
+
18
+ * How to run the test suite
19
+
20
+ * Services (job queues, cache servers, search engines, etc.)
21
+
22
+ * Deployment instructions
23
+
24
+ * ...
@@ -0,0 +1,6 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require_relative 'config/application'
5
+
6
+ Rails.application.load_tasks
@@ -0,0 +1,2 @@
1
+ //= link_tree ../images
2
+ //= link_directory ../stylesheets .css
@@ -0,0 +1,15 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, or any plugin's
6
+ * vendor/assets/stylesheets directory can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
10
+ * files in this directory. Styles in this file should be added after the last require_* statement.
11
+ * It is generally better to create a new file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,4 @@
1
+ module ApplicationCable
2
+ class Channel < ActionCable::Channel::Base
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module ApplicationCable
2
+ class Connection < ActionCable::Connection::Base
3
+ end
4
+ end
@@ -0,0 +1,2 @@
1
+ class ApplicationController < ActionController::Base
2
+ end
@@ -0,0 +1,2 @@
1
+ module ApplicationHelper
2
+ end
@@ -0,0 +1,6 @@
1
+ // Action Cable provides the framework to deal with WebSockets in Rails.
2
+ // You can generate new channels where WebSocket features live using the `rails generate channel` command.
3
+
4
+ import { createConsumer } from "@rails/actioncable"
5
+
6
+ export default createConsumer()
@@ -0,0 +1,5 @@
1
+ // Load all the channels within this directory and all subdirectories.
2
+ // Channel files must be named *_channel.js.
3
+
4
+ const channels = require.context('.', true, /_channel\.js$/)
5
+ channels.keys().forEach(channels)
@@ -0,0 +1,17 @@
1
+ // This file is automatically compiled by Webpack, along with any other files
2
+ // present in this directory. You're encouraged to place your actual application logic in
3
+ // a relevant structure within app/javascript and only use these pack files to reference
4
+ // that code so it'll be compiled.
5
+
6
+ require("@rails/ujs").start()
7
+ require("turbolinks").start()
8
+ require("@rails/activestorage").start()
9
+ require("channels")
10
+
11
+
12
+ // Uncomment to copy all static images under ../images to the output folder and reference
13
+ // them with the image_pack_tag helper in views (e.g <%= image_pack_tag 'rails.png' %>)
14
+ // or the `imagePath` JavaScript helper below.
15
+ //
16
+ // const images = require.context('../images', true)
17
+ // const imagePath = (name) => images(name, true)
@@ -0,0 +1,7 @@
1
+ class ApplicationJob < ActiveJob::Base
2
+ # Automatically retry jobs that encountered a deadlock
3
+ # retry_on ActiveRecord::Deadlocked
4
+
5
+ # Most jobs are safe to ignore if the underlying records are no longer available
6
+ # discard_on ActiveJob::DeserializationError
7
+ end
@@ -0,0 +1,4 @@
1
+ class ApplicationMailer < ActionMailer::Base
2
+ default from: 'from@example.com'
3
+ layout 'mailer'
4
+ end
@@ -0,0 +1,3 @@
1
+ class ApplicationRecord < ActiveRecord::Base
2
+ self.abstract_class = true
3
+ end
@@ -0,0 +1,15 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Dummy</title>
5
+ <%= csrf_meta_tags %>
6
+ <%= csp_meta_tag %>
7
+
8
+ <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
9
+ <%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %>
10
+ </head>
11
+
12
+ <body>
13
+ <%= yield %>
14
+ </body>
15
+ </html>
@@ -0,0 +1,13 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5
+ <style>
6
+ /* Email styles need to be inline */
7
+ </style>
8
+ </head>
9
+
10
+ <body>
11
+ <%= yield %>
12
+ </body>
13
+ </html>
@@ -0,0 +1 @@
1
+ <%= yield %>
@@ -0,0 +1,114 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'bundle' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require "rubygems"
12
+
13
+ m = Module.new do
14
+ module_function
15
+
16
+ def invoked_as_script?
17
+ File.expand_path($0) == File.expand_path(__FILE__)
18
+ end
19
+
20
+ def env_var_version
21
+ ENV["BUNDLER_VERSION"]
22
+ end
23
+
24
+ def cli_arg_version
25
+ return unless invoked_as_script? # don't want to hijack other binstubs
26
+ return unless "update".start_with?(ARGV.first || " ") # must be running `bundle update`
27
+ bundler_version = nil
28
+ update_index = nil
29
+ ARGV.each_with_index do |a, i|
30
+ if update_index && update_index.succ == i && a =~ Gem::Version::ANCHORED_VERSION_PATTERN
31
+ bundler_version = a
32
+ end
33
+ next unless a =~ /\A--bundler(?:[= ](#{Gem::Version::VERSION_PATTERN}))?\z/
34
+ bundler_version = $1
35
+ update_index = i
36
+ end
37
+ bundler_version
38
+ end
39
+
40
+ def gemfile
41
+ gemfile = ENV["BUNDLE_GEMFILE"]
42
+ return gemfile if gemfile && !gemfile.empty?
43
+
44
+ File.expand_path("../../Gemfile", __FILE__)
45
+ end
46
+
47
+ def lockfile
48
+ lockfile =
49
+ case File.basename(gemfile)
50
+ when "gems.rb" then gemfile.sub(/\.rb$/, gemfile)
51
+ else "#{gemfile}.lock"
52
+ end
53
+ File.expand_path(lockfile)
54
+ end
55
+
56
+ def lockfile_version
57
+ return unless File.file?(lockfile)
58
+ lockfile_contents = File.read(lockfile)
59
+ return unless lockfile_contents =~ /\n\nBUNDLED WITH\n\s{2,}(#{Gem::Version::VERSION_PATTERN})\n/
60
+ Regexp.last_match(1)
61
+ end
62
+
63
+ def bundler_version
64
+ @bundler_version ||=
65
+ env_var_version || cli_arg_version ||
66
+ lockfile_version
67
+ end
68
+
69
+ def bundler_requirement
70
+ return "#{Gem::Requirement.default}.a" unless bundler_version
71
+
72
+ bundler_gem_version = Gem::Version.new(bundler_version)
73
+
74
+ requirement = bundler_gem_version.approximate_recommendation
75
+
76
+ return requirement unless Gem::Version.new(Gem::VERSION) < Gem::Version.new("2.7.0")
77
+
78
+ requirement += ".a" if bundler_gem_version.prerelease?
79
+
80
+ requirement
81
+ end
82
+
83
+ def load_bundler!
84
+ ENV["BUNDLE_GEMFILE"] ||= gemfile
85
+
86
+ activate_bundler
87
+ end
88
+
89
+ def activate_bundler
90
+ gem_error = activation_error_handling do
91
+ gem "bundler", bundler_requirement
92
+ end
93
+ return if gem_error.nil?
94
+ require_error = activation_error_handling do
95
+ require "bundler/version"
96
+ end
97
+ return if require_error.nil? && Gem::Requirement.new(bundler_requirement).satisfied_by?(Gem::Version.new(Bundler::VERSION))
98
+ warn "Activating bundler (#{bundler_requirement}) failed:\n#{gem_error.message}\n\nTo install the version of bundler this project requires, run `gem install bundler -v '#{bundler_requirement}'`"
99
+ exit 42
100
+ end
101
+
102
+ def activation_error_handling
103
+ yield
104
+ nil
105
+ rescue StandardError, LoadError => e
106
+ e
107
+ end
108
+ end
109
+
110
+ m.load_bundler!
111
+
112
+ if m.invoked_as_script?
113
+ load Gem.bin_path("bundler", "bundle")
114
+ end