impuri 0.11.0 → 0.12.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: 137b242477de26374948f92a7033db38de59a1b08e5e53eceeca18e3c3c94d12
4
- data.tar.gz: c918d32a40519df5d149faa8cc5d2b48cfd0abf5fcb3a1f2d684380cfa4250c4
3
+ metadata.gz: c72a1dd69d974933264297f60ee3a7c049384798d1ea7a03f93dee06edbc1d2a
4
+ data.tar.gz: 1f2fb098d5be4b9fa995234f82efe16a68faa0b9d085f96626d6bafef4fa357b
5
5
  SHA512:
6
- metadata.gz: 54455a74f4486946e2948b1bed205a70af70d00c95dd453bc5a2c64382508be00dd6c2a4387d06355c36ef7bf0bdf83609be9b1211f9a5d5d1061b1ac4ead639
7
- data.tar.gz: 350b3ba2ba2a9bf71696ceb903bf5961533f454301910bc0dcbd6c465f066cfa69223dc06ada2ad3ba5d5ea4a9f3791001004e04bca28f4ceb8b17bc623691fa
6
+ metadata.gz: 1188cc96a712f06445506d575cdb70c5d318a5cd8fe46b378aa96b7fa1a2a35d8d5287781d0be7f24f94b8f02f5d8e5414834daecc10287b276b9e22b0b06f9e
7
+ data.tar.gz: fef2af493ff7a99a0a4dad6d8abaea054d79c30de505867275f1121a279e2ce676a2d3387b979d13fc20b913d8acdbd112ca2d83303554eb065fd35698065bc8
data/CHANGELOG CHANGED
@@ -1,5 +1,16 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 20260808
4
+
5
+ 0.12.0: + ImpURI#to_ssh, for going the other way.
6
+
7
+ 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.
8
+ 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.
9
+ 3. + has_colon_path_separator? is what tells the two apart, and it was already here.
10
+ 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.
11
+ 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.
12
+ 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.
13
+
3
14
  ## 20260805
4
15
 
5
16
  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 )
@@ -2,5 +2,5 @@
2
2
  # ImpURI::VERSION
3
3
 
4
4
  class ImpURI
5
- VERSION = '0.11.0'
5
+ VERSION = '0.12.0'
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
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.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - thoran