gem_kit-release 0.3.2 → 0.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d9d6b16c56ad134e56b75cb00642a0a5f01ba96c6d7b620854736b871444b5aa
4
- data.tar.gz: c3b718404bb08947a3df23e822a3edb5dc9ae7470da3605272b9d3e6f87b1dda
3
+ metadata.gz: '028c5393e0908e49e47886256eb800f21382125f148bcd378bc6d2214fac27c2'
4
+ data.tar.gz: 85cd0ed8b03d81d4efcf0c63579b0046e273eb52eb36f9af36ab09fa8c972de8
5
5
  SHA512:
6
- metadata.gz: ff045009cdcf213639c10607dfc0bffbc3e03f49e00ae2c34d2e2e50f26b13ffdcd2910d2a00f0b1311ea73ddfcf7318fc75196ff3b5a0960be9be63d3484bf9
7
- data.tar.gz: 4a16c794925df5faaa54e1a0fe3b2429ba3ceddc578e3da8b45fadbbdead1b947eb29c308d50ae27db1a5e0ef9fb7a7e281dbde3762ef8d923df649bf92636a3
6
+ metadata.gz: d5d1107714f5da3a524c06a40eac52b782c71d92a0ca90972c43c5e46c9bfd53bc6bd3cc6490bd3af43ed394eec825787ab30031b05bec192dcaa967b679bdd1
7
+ data.tar.gz: a890866fbb74226735ed5852d2b8fab0accf513cbe529b5ff505fbde0e0f7657f5d30e500088cbd602378fbf266c6f2277dbac8f7cb80c1cf4ce669fc39dba88
@@ -156,24 +156,23 @@ module GemKit
156
156
  # But a hyphenated name whose library is a SINGLE module does not nest.
157
157
  # `ag-ui` is lib/ag_ui.rb holding `module AgUi` — hyphen as underscore —
158
158
  # and the nested form names lib/ag/ui.rb, a file that was never there.
159
- # Both layouts are conventional and the name alone cannot tell them
160
- # apart, so ask the tree: whichever exists is what this project is.
161
159
  #
162
- # When neither exists the nested form wins, because that is what
160
+ # A third belongs to bindings. `oo7-rb` and `sqlite3-ruby` are a library
161
+ # name wearing a suffix that says which language binds it, and the library
162
+ # underneath drops it: lib/oo7.rb holding `module Oo7`, with
163
+ # lib/oo7/version.rb beside it. Often the suffix is only there because
164
+ # RubyGems would not give up the bare name. The nested form names
165
+ # lib/oo7/rb.rb and the flat one lib/oo7_rb.rb, neither of which was ever
166
+ # there, so without this a binding gem cannot be bumped at all.
167
+ #
168
+ # All three are conventional and the name alone cannot tell them apart, so
169
+ # ask the tree: whichever exists is what this project is.
170
+ #
171
+ # When none exists the nested form wins, because that is what
163
172
  # `bundle gem` would have produced and a project with no library yet is
164
173
  # about to become one.
165
174
  def library_segments
166
- nested = name.split("-")
167
- if exists_under_lib?(nested)
168
- nested
169
- else
170
- flat = [name.tr("-", "_")]
171
- if exists_under_lib?(flat)
172
- flat
173
- else
174
- nested
175
- end
176
- end
175
+ layouts.find { |segments| exists_under_lib?(segments) } || nested_layout
177
176
  end
178
177
 
179
178
  # Load the library, so Deprecate's registry reflects this project.
@@ -193,6 +192,31 @@ module GemKit
193
192
 
194
193
  private
195
194
 
195
+ # The suffixes a binding gem wears, which its library drops.
196
+ BINDING_SUFFIXES = %w[rb ruby].freeze
197
+
198
+ # What a hyphenated name could mean, most conventional first. A name with
199
+ # no hyphen in it has exactly one meaning and the list says so.
200
+ def layouts
201
+ [nested_layout, flat_layout, *binding_layout].uniq
202
+ end
203
+
204
+ def nested_layout = name.split("-")
205
+
206
+ def flat_layout = [name.tr("-", "_")]
207
+
208
+ # [["oo7"]] for "oo7-rb"; nothing for a name wearing no binding suffix,
209
+ # and nothing for one that is only the suffix.
210
+ def binding_layout
211
+ nested_layout.then do |segments|
212
+ if segments.length > 1 && BINDING_SUFFIXES.include?(segments.last)
213
+ [segments[0..-2]]
214
+ else
215
+ []
216
+ end
217
+ end
218
+ end
219
+
196
220
  # A layout is present if the entry file is there, or the directory it
197
221
  # would hold — a gem is free to ship lib/foo/ without lib/foo.rb.
198
222
  def exists_under_lib?(segments)
@@ -208,22 +232,29 @@ __END__
208
232
  describe "gem_kit/release/project" do
209
233
  require "tmpdir"
210
234
 
211
- # A throwaway gem. `layout:` picks between the two conventions a hyphenated
235
+ # A throwaway gem. `layout:` picks between the three conventions a hyphenated
212
236
  # name can follow: :nested is `bundle gem`'s lib/gem_kit/release, :flat is a
213
- # single-module gem's lib/ag_ui.
237
+ # single-module gem's lib/ag_ui, and :binding is a bindings gem's lib/oo7 for
238
+ # a gem called oo7-rb.
214
239
  with_project = lambda do |name: "demo", version: "1.2.3", layout: :nested, &block|
215
240
  Dir.mktmpdir do |dir|
216
- if layout == :flat
217
- path = [name.tr("-", "_")]
218
- else
219
- path = name.split("-")
241
+ case layout
242
+ when :flat then path = [name.tr("-", "_")]
243
+ when :binding then path = name.split("-")[0..-2]
244
+ else path = name.split("-")
220
245
  end
221
246
  FileUtils.mkdir_p(File.join(dir, "lib", *path))
222
- File.write(File.join(dir, "lib", *path, "version.rb"), <<~RUBY)
223
- module #{path.map { |p| p.split("_").map(&:capitalize).join }.join("::")}
224
- VERSION = "#{version}"
225
- end
226
- RUBY
247
+
248
+ # Nested blocks rather than `module A::B`, which is only valid once A
249
+ # exists -- and a throwaway gem's outermost constant never does. The one
250
+ # hyphenated name that got away with it was gem_kit-release, because this
251
+ # process has GemKit defined already.
252
+ constants = path.map { |segment| segment.split("_").map(&:capitalize).join }
253
+ lines = constants.each_with_index.map { |constant, depth| "#{" " * depth}module #{constant}" }
254
+ lines << "#{" " * constants.length}VERSION = #{version.inspect}"
255
+ lines.concat(Array.new(constants.length) { |depth| "#{" " * (constants.length - 1 - depth)}end" })
256
+
257
+ File.write(File.join(dir, "lib", *path, "version.rb"), "#{lines.join("\n")}\n")
227
258
  File.write(File.join(dir, "#{name}.gemspec"), <<~RUBY)
228
259
  require_relative "lib/#{path.join("/")}/version"
229
260
  Gem::Specification.new do |spec|
@@ -277,6 +308,44 @@ describe "gem_kit/release/project" do
277
308
  end
278
309
  end
279
310
 
311
+ # A bindings gem drops the suffix: oo7-rb is lib/oo7.rb and lib/oo7/version.rb,
312
+ # which neither of the other two layouts names. Found the hard way -- the gem
313
+ # was called oo7-rb only because RubyGems holds `oo7` for something else, and
314
+ # `gem kit bump` then wrote to lib/oo7/rb/version.rb, a path nothing had.
315
+ it "reads a bindings layout, whose library drops the suffix, off the tree" do
316
+ with_project.call(name: "oo7-rb", layout: :binding) do |dir|
317
+ project = GemKit::Release::Project.detect(dir)
318
+ project.require_path.should == "oo7"
319
+ project.version_file.should == File.join(dir, "lib/oo7/version.rb")
320
+ end
321
+ end
322
+
323
+ it "reads a -ruby suffix the same way" do
324
+ with_project.call(name: "sqlite3-ruby", layout: :binding) do |dir|
325
+ project = GemKit::Release::Project.detect(dir)
326
+ project.version_file.should == File.join(dir, "lib/sqlite3/version.rb")
327
+ end
328
+ end
329
+
330
+ # The suffix is only dropped when the tree says so. A gem that genuinely nests
331
+ # under a segment called "rb" keeps it.
332
+ it "keeps a nested layout that really does end in rb" do
333
+ with_project.call(name: "thing-rb", layout: :nested) do |dir|
334
+ project = GemKit::Release::Project.detect(dir)
335
+ project.require_path.should == "thing/rb"
336
+ project.version_file.should == File.join(dir, "lib/thing/rb/version.rb")
337
+ end
338
+ end
339
+
340
+ # "release" is not a binding suffix, so a name ending in something else is
341
+ # untouched by any of this.
342
+ it "leaves a hyphenated name that wears no binding suffix alone" do
343
+ with_project.call(name: "gem_kit-release", layout: :nested) do |dir|
344
+ project = GemKit::Release::Project.detect(dir)
345
+ project.require_path.should == "gem_kit/release"
346
+ end
347
+ end
348
+
280
349
  # Nesting stays the default: it is what `bundle gem` produces, so it is what
281
350
  # a project with no library yet is about to become.
282
351
  it "falls back to the nested layout when neither is on disk" do
@@ -2,6 +2,6 @@
2
2
 
3
3
  module GemKit
4
4
  module Release
5
- VERSION = "0.3.2"
5
+ VERSION = "0.3.3"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gem_kit-release
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Kidd