@@ -104,6 +104,39 @@ def self.lockfile_name(gemfile = self.gemfile&.filename)
104
104
"Gemfile.lock"
105
105
end
106
106
107
+ def self . with_root_store
108
+ app_store = Gel ::Environment . store
109
+
110
+ base_store = app_store
111
+ base_store = base_store . inner if base_store . is_a? ( Gel ::LockedStore )
112
+
113
+ # Work around the fact Gel::Environment is a singleton: we really
114
+ # want to treat the environment we're running in separately from
115
+ # the application's environment we're working on. But for now, we
116
+ # can just cheat and swap them.
117
+ @store = base_store
118
+
119
+ yield base_store
120
+ ensure
121
+ @store = app_store
122
+ end
123
+
124
+ def self . auto_install_pub_grub!
125
+ with_root_store do |base_store |
126
+ base_store . monitor . synchronize do
127
+ if base_store . each ( "pub_grub" ) . none?
128
+ require_relative "work_pool"
129
+
130
+ Gel ::WorkPool . new ( 2 ) do |work_pool |
131
+ catalog = Gel ::Catalog . new ( "https://rubygems.org" , work_pool : work_pool )
132
+
133
+ install_gem ( [ catalog ] , "pub_grub" , [ ">= 0.5.0" ] )
134
+ end
135
+ end
136
+ end
137
+ end
138
+ end
139
+
107
140
def self . lock ( store : store ( ) , output : nil , gemfile : Gel ::Environment . load_gemfile , lockfile : Gel ::Environment . lockfile_name , catalog_options : { } , preference_strategy : nil )
108
141
output = nil if $DEBUG
109
142
@@ -165,31 +198,9 @@ def self.lock(store: store(), output: nil, gemfile: Gel::Environment.load_gemfil
165
198
end
166
199
end
167
200
168
- begin
169
- app_store = Gel ::Environment . store
170
-
171
- base_store = app_store
172
- base_store = base_store . inner if base_store . is_a? ( Gel ::LockedStore )
173
-
174
- # Work around the fact Gel::Environment is a singleton: we really
175
- # want to treat the environment we're running in separately from
176
- # the application's environment we're working on. But for now, we
177
- # can just cheat and swap them.
178
- @store = base_store
179
-
180
- if base_store . each ( "pub_grub" ) . none?
181
- require_relative "work_pool"
182
-
183
- Gel ::WorkPool . new ( 2 ) do |work_pool |
184
- catalog = Gel ::Catalog . new ( "https://rubygems.org" , work_pool : work_pool )
185
-
186
- install_gem ( [ catalog ] , "pub_grub" , [ ">= 0.5.0" ] )
187
- end
188
- end
189
-
201
+ auto_install_pub_grub!
202
+ with_root_store do
190
203
gem "pub_grub"
191
- ensure
192
- @store = app_store
193
204
end
194
205
require_relative "pub_grub/source"
195
206
0 commit comments