gem_kit-release 0.3.3 → 0.4.0

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: '028c5393e0908e49e47886256eb800f21382125f148bcd378bc6d2214fac27c2'
4
- data.tar.gz: 85cd0ed8b03d81d4efcf0c63579b0046e273eb52eb36f9af36ab09fa8c972de8
3
+ metadata.gz: 1b647f1b210715c92fd0dfb4235b990a4ea766d436b620cc97deda754f5623c8
4
+ data.tar.gz: a1a2738c057847c90265c5b33fc61cd339dd9591d099b28043b1838ac5498327
5
5
  SHA512:
6
- metadata.gz: d5d1107714f5da3a524c06a40eac52b782c71d92a0ca90972c43c5e46c9bfd53bc6bd3cc6490bd3af43ed394eec825787ab30031b05bec192dcaa967b679bdd1
7
- data.tar.gz: a890866fbb74226735ed5852d2b8fab0accf513cbe529b5ff505fbde0e0f7657f5d30e500088cbd602378fbf266c6f2277dbac8f7cb80c1cf4ce669fc39dba88
6
+ metadata.gz: 4b540202a76af4a8433beb465679cdab18fc163fd63d8396da4cb23da73bf4e31c4b6ee9f436a500a48bf69706fd20b865c86e68577c6e9b4191a2ab4ae940db
7
+ data.tar.gz: 84d87decbd5c7fc9053124dd11389ca3faecbfd78041ec4164077963c3dda4c77b64701fef00e2a955dec248e7cb23312918a0629e1de26d10637c20e9deeab0
@@ -165,14 +165,24 @@ module GemKit
165
165
  # lib/oo7/rb.rb and the flat one lib/oo7_rb.rb, neither of which was ever
166
166
  # there, so without this a binding gem cannot be bumped at all.
167
167
  #
168
- # All three are conventional and the name alone cannot tell them apart, so
168
+ # A fourth wears that suffix after a DOT rather than a hyphen: `clippy.rb`,
169
+ # `vue.rb`, `d3.rb`. RubyGems allows a dot in a name, and the convention
170
+ # is the same as the hyphenated binding above — the library drops the
171
+ # suffix, so lib/clippy.rb holds `module Clippy` and the version sits at
172
+ # lib/clippy/version.rb. None of the hyphen layouts sees this: splitting
173
+ # "clippy.rb" on "-" yields one segment that still has the dot in it, so
174
+ # the inferred path was lib/clippy.rb/version.rb — a directory whose name
175
+ # ends in .rb, which nothing has.
176
+ #
177
+ # All four are conventional and the name alone cannot tell them apart, so
169
178
  # ask the tree: whichever exists is what this project is.
170
179
  #
171
180
  # When none exists the nested form wins, because that is what
172
181
  # `bundle gem` would have produced and a project with no library yet is
173
- # about to become one.
182
+ # about to become one — except for a dotted name, which `bundle gem`
183
+ # cannot produce at all, and whose only convention is the dotted one.
174
184
  def library_segments
175
- layouts.find { |segments| exists_under_lib?(segments) } || nested_layout
185
+ layouts.find { |segments| exists_under_lib?(segments) } || default_layout
176
186
  end
177
187
 
178
188
  # Load the library, so Deprecate's registry reflects this project.
@@ -195,16 +205,35 @@ module GemKit
195
205
  # The suffixes a binding gem wears, which its library drops.
196
206
  BINDING_SUFFIXES = %w[rb ruby].freeze
197
207
 
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.
208
+ # What a name could mean, most conventional first. A name with neither
209
+ # a hyphen nor a dotted suffix in it has exactly one meaning and the
210
+ # list says so.
200
211
  def layouts
201
- [nested_layout, flat_layout, *binding_layout].uniq
212
+ [*dotted_layout, nested_layout, flat_layout, *binding_layout].uniq
202
213
  end
203
214
 
215
+ # Nesting is `bundle gem`'s doing and so the usual default, but
216
+ # `bundle gem` will not take a dotted name, so there is nothing for a
217
+ # dotted one to fall back to but itself.
218
+ def default_layout = dotted_layout.first || nested_layout
219
+
204
220
  def nested_layout = name.split("-")
205
221
 
206
222
  def flat_layout = [name.tr("-", "_")]
207
223
 
224
+ # [["clippy"]] for "clippy.rb"; nothing for a name with no dot, and
225
+ # nothing for a dot that is not a language suffix, so a hypothetical
226
+ # "foo.bar" is left to the layouts above.
227
+ def dotted_layout
228
+ name.split(".").then do |segments|
229
+ if segments.length == 2 && BINDING_SUFFIXES.include?(segments.last)
230
+ [[segments.first]]
231
+ else
232
+ []
233
+ end
234
+ end
235
+ end
236
+
208
237
  # [["oo7"]] for "oo7-rb"; nothing for a name wearing no binding suffix,
209
238
  # and nothing for one that is only the suffix.
210
239
  def binding_layout
@@ -241,6 +270,7 @@ describe "gem_kit/release/project" do
241
270
  case layout
242
271
  when :flat then path = [name.tr("-", "_")]
243
272
  when :binding then path = name.split("-")[0..-2]
273
+ when :dotted then path = [name.split(".").first]
244
274
  else path = name.split("-")
245
275
  end
246
276
  FileUtils.mkdir_p(File.join(dir, "lib", *path))
@@ -337,6 +367,83 @@ describe "gem_kit/release/project" do
337
367
  end
338
368
  end
339
369
 
370
+ # A dotted suffix is the same idea as the hyphenated binding above, and the
371
+ # one RubyGems name shape that none of the hyphen layouts can see: splitting
372
+ # "clippy.rb" on "-" leaves the dot in the segment, so the inferred path was
373
+ # lib/clippy.rb/version.rb -- a directory ending in .rb, which nothing has.
374
+ it "reads a dotted bindings layout, whose library drops the suffix" do
375
+ with_project.call(name: "clippy.rb", layout: :dotted) do |dir|
376
+ project = GemKit::Release::Project.detect(dir)
377
+ project.name.should == "clippy.rb"
378
+ project.require_path.should == "clippy"
379
+ project.version_file.should == File.join(dir, "lib/clippy/version.rb")
380
+ end
381
+ end
382
+
383
+ it "reads a dotted .ruby suffix the same way" do
384
+ with_project.call(name: "sqlite3.ruby", layout: :dotted) do |dir|
385
+ GemKit::Release::Project.detect(dir).version_file
386
+ .should == File.join(dir, "lib/sqlite3/version.rb")
387
+ end
388
+ end
389
+
390
+ # `bundle gem` will not take a dotted name, so unlike the hyphen cases there
391
+ # is no nested convention for an empty tree to fall back to.
392
+ it "falls back to the dotted layout when nothing is on disk yet" do
393
+ Dir.mktmpdir do |dir|
394
+ File.write(File.join(dir, "clippy.rb.gemspec"), <<~RUBY)
395
+ Gem::Specification.new do |spec|
396
+ spec.name = "clippy.rb"
397
+ spec.version = "0.1.0"
398
+ spec.authors = ["x"]
399
+ spec.summary = "x"
400
+ spec.files = []
401
+ end
402
+ RUBY
403
+ project = GemKit::Release::Project.detect(dir)
404
+ project.require_path.should == "clippy"
405
+ project.version_file.should == File.join(dir, "lib/clippy/version.rb")
406
+ end
407
+ end
408
+
409
+ # The entry file alone is enough: a dotted gem's lib/clippy.rb is exactly
410
+ # what the nested layout would mistake for its own directory.
411
+ it "recognises the dotted layout from the entry file alone" do
412
+ Dir.mktmpdir do |dir|
413
+ FileUtils.mkdir_p(File.join(dir, "lib"))
414
+ File.write(File.join(dir, "lib", "clippy.rb"), "module Clippy
415
+ end
416
+ ")
417
+ File.write(File.join(dir, "clippy.rb.gemspec"), <<~RUBY)
418
+ Gem::Specification.new do |spec|
419
+ spec.name = "clippy.rb"
420
+ spec.version = "0.1.0"
421
+ spec.authors = ["x"]
422
+ spec.summary = "x"
423
+ spec.files = []
424
+ end
425
+ RUBY
426
+ GemKit::Release::Project.detect(dir).require_path.should == "clippy"
427
+ end
428
+ end
429
+
430
+ # Only a language suffix is dropped. A dot that means something else is left
431
+ # to the hyphen layouts, so this must not become lib/foo.
432
+ it "leaves a dot that is not a language suffix alone" do
433
+ Dir.mktmpdir do |dir|
434
+ File.write(File.join(dir, "foo.bar.gemspec"), <<~RUBY)
435
+ Gem::Specification.new do |spec|
436
+ spec.name = "foo.bar"
437
+ spec.version = "0.1.0"
438
+ spec.authors = ["x"]
439
+ spec.summary = "x"
440
+ spec.files = []
441
+ end
442
+ RUBY
443
+ GemKit::Release::Project.detect(dir).require_path.should == "foo.bar"
444
+ end
445
+ end
446
+
340
447
  # "release" is not a binding suffix, so a name ending in something else is
341
448
  # untouched by any of this.
342
449
  it "leaves a hyphenated name that wears no binding suffix alone" do
@@ -2,6 +2,6 @@
2
2
 
3
3
  module GemKit
4
4
  module Release
5
- VERSION = "0.3.3"
5
+ VERSION = "0.4.0"
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.3
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Kidd