impuri 0.11.0 → 0.12.1

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: 137b242477de26374948f92a7033db38de59a1b08e5e53eceeca18e3c3c94d12
4
- data.tar.gz: c918d32a40519df5d149faa8cc5d2b48cfd0abf5fcb3a1f2d684380cfa4250c4
3
+ metadata.gz: 7d2f3a83faa4992ce901d71360356ef7d7be186b6eed4c31c2c8a506c902d587
4
+ data.tar.gz: 90e51afb1721b37d287d8ff28e57aed1101b173b8ba9be3d683a8189d052966b
5
5
  SHA512:
6
- metadata.gz: 54455a74f4486946e2948b1bed205a70af70d00c95dd453bc5a2c64382508be00dd6c2a4387d06355c36ef7bf0bdf83609be9b1211f9a5d5d1061b1ac4ead639
7
- data.tar.gz: 350b3ba2ba2a9bf71696ceb903bf5961533f454301910bc0dcbd6c465f066cfa69223dc06ada2ad3ba5d5ea4a9f3791001004e04bca28f4ceb8b17bc623691fa
6
+ metadata.gz: 06fcf13867417ffdd2fb9d43176065dba97397053f41ae503094c096b44f18b324b2b18c666a30708efeaca1501aeeed3a1e270be010f42a82a85f9d055d686b
7
+ data.tar.gz: 564e3c7c97652c1aaeac254467a78252ba25edd63ccd06635f3a49d436e1f0c32f7483ab796cf9b65601d93bcb84362f2ff754c0f3f20bebfb4221125981d6bb
data/CHANGELOG CHANGED
@@ -1,5 +1,27 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 20260819
4
+
5
+ 0.12.1: Tidy the gemspec, fill in its metadata, and guard both with a test.
6
+
7
+ 1. ~ impuri.gemspec: + a header comment naming the file, as every other file here carries, and + trailing commas to the last element of spec.files and spec.development_dependencies, so that adding to either touches one line rather than two. ~ spec.files reordered, the globs first and the loose files alphabetically after them, as moby and measurand have it. The globs are what the gem is and the rest is paperwork, so adding paperwork now never disturbs them. This repo had followed namo and http, which pin the gemspec first and put the globs last.
8
+ 2. ~ impuri.gemspec: + spec.metadata, being bug_tracker_uri, changelog_uri, source_code_uri and documentation_uri, as moby carries. These are the links rubygems shows beside the gem, and with none declared the page offers the homepage alone. The blob URLs name master, this repository's default branch, where moby's name main.
9
+ 3. + test/gemspec_test.rb: that the specification validates, that it pins no date, that its version is ImpURI::VERSION rather than a literal, that the four metadata keys are declared and that no blob link names a branch other than master, that it declares no runtime dependencies, and which development dependencies it declares. A link to a branch which does not exist is worse than no link, reading as a broken page rather than an absent one, and nothing else here would catch a rename. Modelled on moby's, which is where this pair of tests was settled.
10
+ 4. ~ test/ImpURI.rb: + require 'gemspec_test', the loader naming each test file by hand.
11
+ 5. ~ ImpURI::VERSION: /0.12.0/0.12.1/
12
+
13
+
14
+ ## 20260808
15
+
16
+ 0.12.0: + ImpURI#to_ssh, for going the other way.
17
+
18
+ 1. + ImpURI#to_ssh: the same resource as an ssh/scp descriptor, being [username@]hostname:path. Parsing both forms was the point of this from the start, and there was a renderer for neither of them beyond to_s giving back what it was handed.
19
+ 2. + The two paths are not the same kind of path, which is the whole of what makes this worth a method rather than a string interpolation. After a colon, a leading slash is the difference between a path from the root and one from the login directory, so a descriptor which arrived that way is returned exactly as it came. After a slash, that slash stood between the hostname and the path rather than anchoring it, so it is not carried into a form where it would say the other thing: github.com/thoran/lineage gives github.com:thoran/lineage and not github.com:/thoran/lineage.
20
+ 3. + has_colon_path_separator? is what tells the two apart, and it was already here.
21
+ 4. + ImpURI#username_with_separator, alongside the userinfo_with_separator and credentials_with_separator which were already here. to_ssh renders the username alone: ssh has no use for a password in this position, and a port number has nowhere to go in this form either, so both are dropped along with the scheme.
22
+ 5. + Nine tests over both directions, the password, the port number, and a descriptor with no path at all, which gives hostname and a colon, that being the login directory.
23
+ 6. Written for git-boot, which had been interpolating "#{username}@#{hostname}:#{path}" and getting git@github.com:/thoran/lineage for its trouble: a URI path spliced into a position where the leading slash means something else. That is a fault in the caller and not here, but a library which parses both forms may as well render both.
24
+
3
25
  ## 20260805
4
26
 
5
27
  0.11.0: Name the entry point and the gemspec for the gem.
data/README.md CHANGED
@@ -60,6 +60,28 @@ impuri.parameters
60
60
  # => {'q' => 'param'}
61
61
  ```
62
62
 
63
+ ### Rendering
64
+
65
+ ```ruby
66
+ impuri.to_s
67
+ # => the string it was given back again
68
+
69
+ ImpURI.new('github.com/thoran/lineage').to_ssh
70
+ # => 'github.com:thoran/lineage'
71
+
72
+ ImpURI.new('git@github.com:thoran/lineage.git').to_ssh
73
+ # => 'git@github.com:thoran/lineage.git'
74
+
75
+ ImpURI.new('user@host.com:/srv/git/thing.git').to_ssh
76
+ # => 'user@host.com:/srv/git/thing.git'
77
+ ```
78
+
79
+ `#to_ssh` renders the same resource as an ssh/scp descriptor, `[username@]hostname:path`.
80
+
81
+ Where the path arrived after a colon it is left as it stands, since a leading slash there is the difference between a path from the root and one from the login directory, and an ssh descriptor is returned unchanged. Where the path arrived after a slash, that slash separated it from the hostname rather than anchoring it, and so is not carried into a form where it would say the other thing.
82
+
83
+ A scheme, a port number and a password are all dropped, this form having no place for any of them.
84
+
63
85
  ## Contributing
64
86
 
65
87
  1. Fork it ( https://github.com/thoran/impuri/fork )
data/impuri.gemspec CHANGED
@@ -1,3 +1,5 @@
1
+ # impuri.gemspec
2
+
1
3
  require_relative './lib/ImpURI/VERSION'
2
4
 
3
5
  class Gem::Specification
@@ -18,20 +20,27 @@ Gem::Specification.new do |spec|
18
20
  spec.homepage = 'https://github.com/thoran/ImpURI'
19
21
  spec.license = 'MIT'
20
22
 
23
+ spec.metadata = {
24
+ 'bug_tracker_uri' => 'https://github.com/thoran/ImpURI/issues',
25
+ 'changelog_uri' => 'https://github.com/thoran/ImpURI/blob/master/CHANGELOG',
26
+ 'source_code_uri' => 'https://github.com/thoran/ImpURI',
27
+ 'documentation_uri' => 'https://github.com/thoran/ImpURI/blob/master/README.md',
28
+ }
29
+
21
30
  spec.required_ruby_version = '>= 2.7'
22
31
  spec.require_paths = ['lib']
23
32
 
24
33
  spec.files = [
25
- 'impuri.gemspec',
34
+ Dir['lib/**/*.rb'],
35
+ Dir['test/**/*.rb'],
26
36
  'CHANGELOG',
27
37
  'Gemfile',
38
+ 'impuri.gemspec',
28
39
  'README.md',
29
40
  'TODO.txt',
30
- Dir['lib/**/*.rb'],
31
- Dir['test/**/*.rb']
32
41
  ].flatten
33
42
 
34
43
  spec.development_dependencies = [
35
- ['minitest', '~> 6.0']
44
+ ['minitest', '~> 6.0'],
36
45
  ]
37
46
  end
@@ -2,5 +2,5 @@
2
2
  # ImpURI::VERSION
3
3
 
4
4
  class ImpURI
5
- VERSION = '0.11.0'
5
+ VERSION = '0.12.1'
6
6
  end
data/lib/impuri.rb CHANGED
@@ -432,6 +432,20 @@ class ImpURI
432
432
  end
433
433
  end
434
434
 
435
+ def username_with_separator
436
+ has_username? ? "#{username}@" : ''
437
+ end
438
+
439
+ # A path which arrived after a colon is left as it stands, a leading slash there being the difference between a path from the root and one from the login directory. A path which arrived after a slash was separated from the hostname by it rather than anchored by it, and so it is not carried into a form where it would mean the other thing.
440
+ def ssh_path
441
+ has_colon_path_separator? ? path : path.to_s.sub(%r{\A/}, '')
442
+ end
443
+
444
+ # The same resource as an ssh/scp descriptor, being [username@]hostname:path. A port number has no place in this form and is dropped, as is a password, ssh having no use for one here.
445
+ def to_ssh
446
+ "#{username_with_separator}#{hostname}:#{ssh_path}"
447
+ end
448
+
435
449
  def to_h
436
450
  {scheme: scheme, username: username, password: password, hostname: hostname, port_number: port_number, path: path, parameter_string: parameter_string}
437
451
  end
@@ -8,11 +8,8 @@ require 'impuri'
8
8
  require 'minitest/autorun'
9
9
 
10
10
  describe ImpURI do
11
-
12
11
  describe 'attribute readers' do
13
-
14
12
  describe 'a very simple http URI' do
15
-
16
13
  let(:impuri){ImpURI.new('http://example.com')}
17
14
 
18
15
  it 'must parse out the scheme' do
@@ -795,11 +792,9 @@ describe ImpURI do
795
792
  _(impuri.path).must_equal 'thoran/ImpURI.git'
796
793
  end
797
794
  end # describe 'an ssh identifier as per Github'
798
-
799
795
  end # describe 'attribute readers'
800
796
 
801
797
  describe 'attribute writers' do
802
-
803
798
  describe 'a very simple http URI' do
804
799
  let(:impuri){ImpURI.new('http://example.com')}
805
800
 
@@ -873,7 +868,75 @@ describe ImpURI do
873
868
  _(impuri.to_s).must_equal 'ftp://user:pass@example2.com:8080/path/to/here?a=1&b=2'
874
869
  end
875
870
  end # describe 'a very simple http URI'
876
-
877
871
  end # describe 'attribute writers'
878
872
 
873
+ describe '#to_ssh' do
874
+ describe 'a URI-style identifier' do
875
+ let(:impuri){ImpURI.new('github.com/thoran/lineage')}
876
+
877
+ # The slash stood between the hostname and the path rather than anchoring
878
+ # the path, and after a colon it would say the path began at the root.
879
+ it 'must not carry the separating slash into the path' do
880
+ _(impuri.to_ssh).must_equal 'github.com:thoran/lineage'
881
+ end
882
+ end # describe 'a URI-style identifier'
883
+
884
+ describe 'a URI-style identifier with a scheme' do
885
+ let(:impuri){ImpURI.new('https://github.com/thoran/lineage')}
886
+
887
+ it 'must leave the scheme out, there being no place for one' do
888
+ _(impuri.to_ssh).must_equal 'github.com:thoran/lineage'
889
+ end
890
+ end # describe 'a URI-style identifier with a scheme'
891
+
892
+ describe 'an ssh identifier with a path from the login directory' do
893
+ let(:impuri){ImpURI.new('git@github.com:thoran/lineage.git')}
894
+
895
+ it 'must return what it was given' do
896
+ _(impuri.to_ssh).must_equal 'git@github.com:thoran/lineage.git'
897
+ end
898
+ end # describe 'an ssh identifier with a path from the login directory'
899
+
900
+ describe 'an ssh identifier with a path from the root' do
901
+ let(:impuri){ImpURI.new('user@host.com:/srv/git/thing.git')}
902
+
903
+ it 'must keep the leading slash, that being the whole of the difference' do
904
+ _(impuri.to_ssh).must_equal 'user@host.com:/srv/git/thing.git'
905
+ end
906
+ end # describe 'an ssh identifier with a path from the root'
907
+
908
+ describe 'an identifier with a password' do
909
+ let(:impuri){ImpURI.new('user:pass@host.com:/srv/git/thing.git')}
910
+
911
+ it 'must render the username alone, ssh having no use for a password here' do
912
+ _(impuri.to_ssh).must_equal 'user@host.com:/srv/git/thing.git'
913
+ end
914
+ end # describe 'an identifier with a password'
915
+
916
+ describe 'an identifier with a port number' do
917
+ let(:impuri){ImpURI.new('http://example.com:8080/a/b')}
918
+
919
+ it 'must drop the port number, this form having nowhere to put one' do
920
+ _(impuri.to_ssh).must_equal 'example.com:a/b'
921
+ end
922
+ end # describe 'an identifier with a port number'
923
+
924
+ describe 'an identifier with no path' do
925
+ let(:impuri){ImpURI.new('example.com')}
926
+
927
+ it 'must return the hostname and a colon, being the login directory' do
928
+ _(impuri.to_ssh).must_equal 'example.com:'
929
+ end
930
+ end # describe 'an identifier with no path'
931
+ end # describe '#to_ssh'
932
+
933
+ describe '#username_with_separator' do
934
+ it 'must return the username and an at sign where there is one' do
935
+ _(ImpURI.new('git@github.com:thoran/lineage.git').username_with_separator).must_equal 'git@'
936
+ end
937
+
938
+ it 'must return an empty string where there is none' do
939
+ _(ImpURI.new('github.com/thoran/lineage').username_with_separator).must_equal ''
940
+ end
941
+ end # describe '#username_with_separator'
879
942
  end
data/test/ImpURI.rb CHANGED
@@ -7,3 +7,4 @@ $LOAD_PATH.unshift(test_dir) unless $LOAD_PATH.include?(test_dir)
7
7
 
8
8
  require 'ImpURI/class_methods'
9
9
  require 'ImpURI/instance_methods'
10
+ require 'gemspec_test'
@@ -0,0 +1,42 @@
1
+ # test/gemspec_test.rb
2
+
3
+ gem 'minitest'
4
+
5
+ $LOAD_PATH.unshift(File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib')))
6
+
7
+ require 'impuri'
8
+ require 'minitest/autorun'
9
+
10
+ describe 'impuri.gemspec' do
11
+ let(:spec){Gem::Specification.load(File.expand_path('../impuri.gemspec', __dir__))}
12
+
13
+ it "is a valid specification" do
14
+ _(spec.validate).must_equal(true)
15
+ end
16
+
17
+ it "does not pin a date" do
18
+ _(spec.date).must_equal(Gem::Specification.new.date)
19
+ end
20
+
21
+ it "takes its version from ImpURI::VERSION" do
22
+ _(spec.version.to_s).must_equal(ImpURI::VERSION)
23
+ end
24
+
25
+ it "declares the metadata links rubygems shows beside the gem" do
26
+ _(spec.metadata.keys.sort) \
27
+ .must_equal(%w{bug_tracker_uri changelog_uri documentation_uri source_code_uri})
28
+ end
29
+
30
+ it "points its metadata at the branch which exists" do
31
+ _(spec.metadata.values.grep(%r{/blob/})).wont_be_empty
32
+ _(spec.metadata.values.grep(%r{/blob/(?!master/)})).must_equal([])
33
+ end
34
+
35
+ it "declares no runtime dependencies, the library standing alone" do
36
+ _(spec.runtime_dependencies).must_equal([])
37
+ end
38
+
39
+ it "declares its development dependencies" do
40
+ _(spec.development_dependencies.map(&:name).sort).must_equal(%w{minitest})
41
+ end
42
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: impuri
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.0
4
+ version: 0.12.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - thoran
@@ -59,10 +59,15 @@ files:
59
59
  - test/ImpURI.rb
60
60
  - test/ImpURI/class_methods.rb
61
61
  - test/ImpURI/instance_methods.rb
62
+ - test/gemspec_test.rb
62
63
  homepage: https://github.com/thoran/ImpURI
63
64
  licenses:
64
65
  - MIT
65
- metadata: {}
66
+ metadata:
67
+ bug_tracker_uri: https://github.com/thoran/ImpURI/issues
68
+ changelog_uri: https://github.com/thoran/ImpURI/blob/master/CHANGELOG
69
+ source_code_uri: https://github.com/thoran/ImpURI
70
+ documentation_uri: https://github.com/thoran/ImpURI/blob/master/README.md
66
71
  rdoc_options: []
67
72
  require_paths:
68
73
  - lib
@@ -77,7 +82,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
77
82
  - !ruby/object:Gem::Version
78
83
  version: '0'
79
84
  requirements: []
80
- rubygems_version: 4.0.17
85
+ rubygems_version: 4.0.18
81
86
  specification_version: 4
82
87
  summary: This is a hand-written non-validating parser for URI's and ssh/scp almost
83
88
  URI resource descriptors.