drain 0.6.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3dea94fa15923f71b70d9dc67df57c6ea196e0cd68e2b8bf68dca52af40b98cc
4
- data.tar.gz: eef6894d11959d219f09bb3c6e9f8a81d04a1c35ff262ca61aca6fe16b44e0c9
3
+ metadata.gz: 8da4d9b373952c13931d7ed377565f1cd60297107413a4230f3cbdc2481af952
4
+ data.tar.gz: ba54f1c1946487b37916d0d6e0a14542d273f3dccd5f86109586cd275d8d2e32
5
5
  SHA512:
6
- metadata.gz: 21cbef6b4255d768f7c4b827edb317432e8c82c19aedc26cd11055c25883f5d09e8f53dc726432b0c0736465ed78800da0e2369a6d87bede7318905c7993eddb
7
- data.tar.gz: 8ca316496349c54e69ef811b6eb2f90326c254d8a95c8b380a45509240d2d50bd0d5dc1765abac63a64ebb127e802224fd2cf4c5481d1b2c6ffe7af8dcbda74a
6
+ metadata.gz: 97028489d945221d6aed71741954a1dec636d2961cf8fa6c22988fa447e8c5548d8450f3c8f0d5dd9d2f25d35ad0e54a7a1d485cf1af667e8f47a462afe86538
7
+ data.tar.gz: bbd72c1baaf24811cc950c7003ec9d5911dadd73ee38cce08d2c80191376f17066e3494ce7b3d63556219fb35af6f30a9a4cdf99d33d3a29302cf87c64d736ae
@@ -1,3 +1,11 @@
1
+ == Release v0.7.0 (2020-07-09) ==
2
+
3
+ * Update test for new uri.rb API
4
+ * uri.rb: Add alias
5
+ * DR::URI
6
+ * utils.rb: switch to amazing_print
7
+ * graph.rb: <<
8
+
1
9
  == Release v0.6.0 (2020-02-26) ==
2
10
 
3
11
  * Add github actions for tests
@@ -213,6 +213,11 @@ module DR
213
213
  end
214
214
  self
215
215
  end
216
+
217
+ # alias << build
218
+ def <<(node, **opts)
219
+ build(node, **opts)
220
+ end
216
221
 
217
222
  def all
218
223
  @nodes.sort
@@ -2,217 +2,232 @@ require "uri"
2
2
  require "delegate"
3
3
 
4
4
  module URI
5
- # From https://github.com/packsaddle/ruby-uri-ssh_git
6
- module Ssh
7
- extend self
8
- # @example
9
- # url = URI::SshGit.parse('git@github.com:packsaddle/ruby-uri-ssh_git.git')
10
- # #=> #<URI::SshGit::Generic git@github.com:packsaddle/ruby-uri-ssh_git.git>
11
- # url.scheme #=> nil
12
- # url.userinfo #=> 'git'
13
- # url.user #=> 'git'
14
- # url.password #=> nil
15
- # url.host #=> 'github.com'
16
- # url.port #=> nil
17
- # url.registry #=> nil
18
- # url.path #=> 'packsaddle/ruby-uri-ssh_git.git'
19
- # url.opaque #=> nil
20
- # url.query #=> nil
21
- # url.fragment #=> nil
22
- # @see http://docs.ruby-lang.org/en/2.2.0/URI/Generic.html
23
- # @param url [String] git repository url via ssh protocol
24
- # @return [Generic] parsed object
25
- protected def internal_parse(uri_string)
26
- host_part, path_part = uri_string&.split(':', 2)
27
- # There may be no user, so reverse the split to make sure host always
28
- # is !nil if host_part was !nil.
29
- host, userinfo = host_part&.split('@', 2)&.reverse
30
- Generic.build(userinfo: userinfo, host: host || uri_string, path: path_part)
31
- end
32
-
33
- # @param url [String] git repository-ish url
34
- # @return [URI::Generic] if url starts ssh
35
- # @return [URI::HTTPS] if url starts https
36
- # @return [URI::SshGit] if url is ssh+git e.g git@example.com:schacon/ticgit.git
37
- def parse(url, force: false)
38
- (ssh_git_url?(url) || force)? URI::Ssh.internal_parse(url) : URI.parse(url)
39
- end
40
-
41
- ## From: https://github.com/packsaddle/ruby-git_clone_url
42
- # @param url [String] git repository-ish url
43
- # @return [Boolean] true if url is git via ssh protocol
44
- def ssh_git_url?(url)
45
- !generic_url?(url)
46
- end
47
-
48
- # @param url [String] git repository-ish url
49
- # @return [Boolean] true if url is https, ssh protocol
50
- def generic_url?(url)
51
- match = %r{\A(\w*)://}.match(url)
52
- !match.nil?
53
- end
54
-
55
- class Generic < ::URI::Generic
56
- # check_host returns `false` for 'foo_bar'
57
- # but in ssh config this can be a valid host
58
- def check_host(_v)
59
- return true
60
- end
61
- # @example
62
- # Generic.build(
63
- # userinfo: 'git',
64
- # host: 'github.com',
65
- # path: 'packsaddle/ruby-uri-ssh_git.git'
66
- # ).to_ssh
67
- # #=> 'git@github.com:packsaddle/ruby-uri-ssh_git.git'
68
- #
69
- # @return [String] git repository url via ssh protocol
70
- def to_ssh(show_path: true)
71
- str = ''
72
- str << "#{user}@" if user && !user.empty?
73
- str << "#{host}"
74
- str << ":#{path}" if path and show_path
75
- str
76
- end
77
- end
78
- end
5
+ # From https://github.com/packsaddle/ruby-uri-ssh_git
6
+ module Ssh
7
+ extend self
8
+ # @example
9
+ # url = URI::Ssh.parse('git@github.com:packsaddle/ruby-uri-ssh_git.git')
10
+ # #=> #<URI::Ssh::Generic git@github.com:packsaddle/ruby-uri-ssh_git.git>
11
+ # url.scheme #=> nil
12
+ # url.userinfo #=> 'git'
13
+ # url.user #=> 'git'
14
+ # url.password #=> nil
15
+ # url.host #=> 'github.com'
16
+ # url.port #=> nil
17
+ # url.registry #=> nil
18
+ # url.path #=> 'packsaddle/ruby-uri-ssh_git.git'
19
+ # url.opaque #=> nil
20
+ # url.query #=> nil
21
+ # url.fragment #=> nil
22
+ # @see http://docs.ruby-lang.org/en/2.2.0/URI/Generic.html
23
+ # @param url [String] git repository url via ssh protocol
24
+ # @return [Generic] parsed object
25
+ protected def internal_parse(uri_string)
26
+ host_part, path_part = uri_string&.split(':', 2)
27
+ # There may be no user, so reverse the split to make sure host always
28
+ # is !nil if host_part was !nil.
29
+ host, userinfo = host_part&.split('@', 2)&.reverse
30
+ Generic.build(userinfo: userinfo, host: host || uri_string, path: path_part)
31
+ end
32
+
33
+ # @param url [String] git repository-ish url
34
+ # @return [URI::Generic] if url starts ssh
35
+ # @return [URI::HTTPS] if url starts https
36
+ # @return [URI::SshGit] if url is ssh+git e.g git@example.com:schacon/ticgit.git
37
+ def parse(url, force: false)
38
+ (ssh_git_url?(url) || force)? ::URI::Ssh.internal_parse(url) : ::URI.parse(url)
39
+ end
40
+
41
+ ## From: https://github.com/packsaddle/ruby-git_clone_url
42
+ # @param url [String] git repository-ish url
43
+ # @return [Boolean] true if url is git via ssh protocol
44
+ def ssh_git_url?(url)
45
+ !generic_url?(url)
46
+ end
47
+
48
+ # @param url [String] git repository-ish url
49
+ # @return [Boolean] true if url is https, ssh protocol
50
+ def generic_url?(url)
51
+ match = %r{\A(\w*)://}.match(url)
52
+ !match.nil?
53
+ end
54
+
55
+ class Generic < ::URI::Generic #URI::Ssh::Generic
56
+ # check_host returns `false` for 'foo_bar'
57
+ # but in ssh config this can be a valid host
58
+ def check_host(_v)
59
+ return true
60
+ end
61
+ # @example
62
+ # URI::Ssh::Generic.build(
63
+ # userinfo: 'git',
64
+ # host: 'github.com',
65
+ # path: 'packsaddle/ruby-uri-ssh_git.git'
66
+ # ).to_ssh
67
+ # #=> 'git@github.com:packsaddle/ruby-uri-ssh_git.git'
68
+ #
69
+ # @return [String] git repository url via ssh protocol
70
+ def to_ssh(show_path: true)
71
+ str = ''
72
+ str << "#{user}@" if user && !user.empty?
73
+ str << "#{host}"
74
+ str << ":#{path}" if path and show_path
75
+ str
76
+ end
77
+ end
78
+ end
79
79
  end
80
80
 
81
81
  module DR
82
- module MailToHelper
83
- # TODO: wrap to= to add user= and host=
84
- end
85
-
86
- # reimplement deprecated escape and unescape methods since
87
- # URI.encode_www_form_component does not encode the same way
88
- # cf the source code of URI::DEFAULT_PARSER.escape
89
- module URIEscape
90
- extend self
91
- def escape(*arg)
92
- URI::DEFAULT_PARSER.escape(*arg)
93
- end
94
- def unescape(*arg)
95
- URI::DEFAULT_PARSER.unescape(*arg)
96
- end
97
- end
98
-
99
- module URIlikeWrapper
100
- def to_h
101
- h = { uri: uri }
102
- components = uri.component
103
- components += %i[user password] if components.include?(:userinfo)
104
- components.each do |m|
105
- v = uri.public_send(m)
106
- v && h[m] = v
107
- end
108
- h
109
- end
110
-
111
- def to_json(_state = nil)
112
- h=to_h
113
- h[:uri]=h[:uri].to_s #h[:uri] is a URIWrapper, so convert it to string so json does not convert it again
114
- h.to_json
115
- end
116
-
117
- def to_public
118
- pub = dup
119
- pub.password = nil
120
- pub.to_s
121
- end
122
-
123
- # uri=u2.merge(uri) does not work if uri is absolute
124
- def reverse_merge(u2)
125
- # return self unless uri.scheme
126
- u2 = u2.clone
127
- u2 = self.class.new(u2) unless u2.is_a?(self.class)
128
- if opaque.nil? == u2.opaque.nil?
129
- u2.soft_merge(self)
130
- else
131
- self
132
- end
133
- end
134
-
135
- # merge(u2) replace self by u2 if u2 is aboslute
136
- # soft_merge looks at each u2 components
137
- def soft_merge(u2)
138
- # we want automatic unescaping of u2 components
139
- u2 = self.class.new(u2) unless u2.is_a?(self.class)
140
- # only merge if we are both opaque or path like
141
- if opaque.nil? == u2.opaque.nil?
142
- components = uri.component
143
- if components.include?(:userinfo)
144
- components += %i[user password]
145
- components.delete(:userinfo)
146
- end
147
- components.each do |m|
148
- # path returns "" by default but we don't want to merge in this case
149
- if u2.respond_to?(m) && (v = u2.public_send(m)) && !((v == "") && (m == :path))
150
- uri.public_send(:"#{m}=", v)
151
- end
152
- end
153
- end
154
- self
155
- end
156
- end
157
-
158
- class URIWrapper < SimpleDelegator
159
- def uri
160
- __getobj__
161
- end
162
-
163
- def uri=(uri)
164
- __setobj__(transform_uri(uri))
165
- end
166
-
167
- include URIlikeWrapper
168
-
169
- def self.parse(s)
170
- new(URI.parse(s))
171
- end
172
-
173
- def self.get_uri_object(uri)
174
- uri = self.parse(uri.to_s) unless uri.is_a?(URI)
175
- uri
176
- end
177
-
178
- private def transform_uri(uri)
179
- # wrap the components around escape/unescape
180
- uri = self.class.get_uri_object(uri)
181
- if uri.is_a?(URI)
182
- components = uri.component
183
- components += %i[user password] if components.include?(:userinfo)
184
- components.each do |m|
185
- uri.define_singleton_method(m) do
186
- r = super()
187
- r && r.is_a?(String) ? URIEscape.unescape(r) : r
188
- # r && r.is_a?(String) ? ::URI.decode_www_form_component(r) : r
189
- end
190
- uri.define_singleton_method(:"#{m}=") do |v|
191
- begin
192
- super(v && v.is_a?(String) ? URIEscape.escape(v) : v)
193
- # super(v && v.is_a?(String) ? ::URI.encode_www_form_component(v) : v)
194
- rescue URI::InvalidURIError => e
195
- warn "#{e} in (#{self}).#{m}=#{v}"
196
- # require 'pry'; binding.pry
197
- end
198
- end
199
- uri.extend(MailToHelper) if uri.is_a?(URI::MailTo)
200
- end
201
- end
202
- uri
203
- end
204
-
205
- # recall that '//user@server' is an uri while 'user@server' is just a path
206
- def initialize(uri)
207
- super
208
- self.uri = uri
209
- end
210
-
211
- class Ssh < URIWrapper
212
- def self.parse(s)
213
- new(URI::Ssh.parse(s))
214
- end
215
- end
216
- end
82
+ module URI
83
+ module MailToHelper
84
+ # TODO: wrap to= to add user= and host=
85
+ end
86
+
87
+ module URIHelpers
88
+ def to_h
89
+ h = { uri: uri }
90
+ components = uri.component
91
+ components += %i[user password] if components.include?(:userinfo)
92
+ components.each do |m|
93
+ v = uri.public_send(m)
94
+ v && h[m] = v
95
+ end
96
+ h
97
+ end
98
+
99
+ def to_json(_state = nil)
100
+ h=to_h
101
+ h[:uri]=h[:uri].to_s #h[:uri] is a URIWrapper, so convert it to string so json does not convert it again
102
+ h.to_json
103
+ end
104
+
105
+ # strip password
106
+ def to_public
107
+ pub = dup
108
+ pub.password = nil
109
+ pub.to_s
110
+ end
111
+
112
+ def strip_user
113
+ pub = dup
114
+ pub.user = nil
115
+ pub.to_s
116
+ end
117
+
118
+ # uri=u2.merge(uri) does not work if uri is absolute
119
+ def reverse_merge(u2)
120
+ # return self unless uri.scheme
121
+ u2 = u2.clone
122
+ u2 = self.class.new(u2) unless u2.is_a?(self.class)
123
+ if opaque.nil? == u2.opaque.nil?
124
+ u2.soft_merge(self)
125
+ else
126
+ self
127
+ end
128
+ end
129
+
130
+ # merge(u2) replace self by u2 if u2 is aboslute
131
+ # soft_merge looks at each u2 components
132
+ def soft_merge(u2)
133
+ # we want automatic unescaping of u2 components
134
+ u2 = self.class.new(u2) unless u2.is_a?(self.class)
135
+ # only merge if we are both opaque or path like
136
+ if opaque.nil? == u2.opaque.nil?
137
+ components = uri.component
138
+ if components.include?(:userinfo)
139
+ components += %i[user password]
140
+ components.delete(:userinfo)
141
+ end
142
+ components.each do |m|
143
+ # path returns "" by default but we don't want to merge in this case
144
+ if u2.respond_to?(m) && (v = u2.public_send(m)) && !((v == "") && (m == :path))
145
+ uri.public_send(:"#{m}=", v)
146
+ end
147
+ end
148
+ end
149
+ self
150
+ end
151
+ end
152
+
153
+ class Wrapper < SimpleDelegator
154
+ def uri
155
+ __getobj__
156
+ end
157
+
158
+ def uri=(uri)
159
+ __setobj__(transform_uri(uri))
160
+ end
161
+
162
+ include URIHelpers
163
+
164
+ def self.parse(s)
165
+ new(::URI.parse(s))
166
+ end
167
+
168
+ def self.get_uri_object(uri)
169
+ uri = self.parse(uri.to_s) unless uri.is_a?(::URI)
170
+ uri
171
+ end
172
+
173
+ private def transform_uri(uri)
174
+ # wrap the components around escape/unescape
175
+ uri = self.class.get_uri_object(uri)
176
+ if uri.is_a?(::URI::Generic)
177
+ uri.extend(URI::MailToHelper) if uri.is_a?(::URI::MailTo)
178
+ components = uri.component
179
+ components += %i[user password] if components.include?(:userinfo)
180
+ components.each do |m|
181
+ uri.define_singleton_method(m) do
182
+ r = super()
183
+ r && r.is_a?(String) ? URI.unescape(r) : r
184
+ # r && r.is_a?(String) ? ::URI.decode_www_form_component(r) : r
185
+ end
186
+ uri.define_singleton_method(:"#{m}=") do |v|
187
+ begin
188
+ super(v && v.is_a?(String) ? URI.escape(v) : v)
189
+ # super(v && v.is_a?(String) ? ::URI.encode_www_form_component(v) : v)
190
+ rescue ::URI::InvalidURIError => e
191
+ warn "#{e} in (#{self}).#{m}=#{v}"
192
+ # require 'pry'; binding.pry
193
+ end
194
+ end
195
+ end
196
+ end
197
+ uri
198
+ end
199
+
200
+ # recall that '//user@server' is an uri while 'user@server' is just a path
201
+ def initialize(uri)
202
+ super
203
+ self.uri = uri
204
+ end
205
+ end
206
+
207
+ class Ssh < Wrapper
208
+ def self.parse(s)
209
+ new(::URI::Ssh.parse(s))
210
+ end
211
+ end
212
+
213
+ # reimplement deprecated escape and unescape methods since
214
+ # URI.encode_www_form_component does not encode the same way
215
+ # cf the source code of URI::DEFAULT_PARSER.escape
216
+ module URIEscape
217
+ extend self
218
+ def escape(*arg)
219
+ ::URI::DEFAULT_PARSER.escape(*arg)
220
+ end
221
+ def unescape(*arg)
222
+ ::URI::DEFAULT_PARSER.unescape(*arg)
223
+ end
224
+ end
225
+ Escape=URIEscape
226
+ extend URIEscape
227
+
228
+ def self.parse(s)
229
+ Wrapper.parse(s)
230
+ end
231
+ end
217
232
 
218
233
  end
@@ -1,28 +1,32 @@
1
1
  module DR
2
2
  module Utils
3
3
  extend self
4
- def pretty_print(string, format: nil, pretty: nil)
4
+ def pretty_print(string, format: nil, pretty: nil, **kw)
5
5
  case format.to_s
6
6
  when "json"
7
7
  require 'json'
8
- return pretty_print(string.to_json, pretty: pretty)
8
+ return pretty_print(string.to_json, pretty: pretty, **kw)
9
9
  when "yaml"
10
10
  require "yaml"
11
- return pretty_print(string.to_yaml, pretty: pretty)
11
+ return pretty_print(string.to_yaml, pretty: pretty, **kw)
12
12
  end
13
13
  pretty = "color" if pretty == nil or pretty == true #default
14
14
  case pretty.to_s
15
- when "ap"
15
+ when "ap", "awesome_print", "amazing_print"
16
16
  begin
17
- require 'ap'
18
- ap string
17
+ require 'amazing_print'
18
+ ap(string, **kw)
19
19
  rescue LoadError,NameError
20
- pretty_print(string,pretty: :pp)
20
+ pretty_print(string,pretty: :pp_color, **kw)
21
21
  end
22
22
  when "color", "pp_color"
23
23
  begin
24
24
  require 'pry'
25
- Pry::ColorPrinter.pp string
25
+ if kw[:multiline] == false #simulate no multiline
26
+ Pry::ColorPrinter.pp string, $DEFAULT_OUTPUT, 9999
27
+ else
28
+ Pry::ColorPrinter.pp string
29
+ end
26
30
  rescue LoadError,NameError
27
31
  pretty_print(string,pretty: :pp)
28
32
  end
@@ -1,4 +1,4 @@
1
1
  module DR
2
2
  # drain version
3
- VERSION = "0.6.0"
3
+ VERSION = "0.7.0"
4
4
  end
@@ -1,9 +1,9 @@
1
1
  require 'helper'
2
2
  require 'dr/base/uri'
3
3
 
4
- describe DR::URIWrapper do
4
+ describe DR::URI::Wrapper do
5
5
  before do
6
- @uri=DR::URIWrapper.new(DR::URIEscape.escape("http://ploum:secret@plam:443/foo bar"))
6
+ @uri=DR::URI::Wrapper.new(DR::URI::Escape.escape("http://ploum:secret@plam:443/foo bar"))
7
7
  end
8
8
  it "Wraps an uri element" do
9
9
  _(@uri.scheme).must_equal "http"
@@ -29,7 +29,7 @@ describe DR::URIWrapper do
29
29
  _(@uri.soft_merge("foo://plim@").to_s).must_equal("foo://plim:secret@plam:443/foo%20bar")
30
30
  end
31
31
  it "Can be reverse merged" do
32
- _(DR::URIWrapper.parse("//user@server").reverse_merge(@uri).to_s).must_equal("http://user:secret@server:443/foo%20bar")
32
+ _(DR::URI::Wrapper.parse("//user@server").reverse_merge(@uri).to_s).must_equal("http://user:secret@server:443/foo%20bar")
33
33
  end
34
34
  end
35
35
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: drain
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Damien Robert
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-02-26 00:00:00.000000000 Z
11
+ date: 2020-10-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
@@ -77,6 +77,7 @@ extra_rdoc_files:
77
77
  - LICENSE.txt
78
78
  - README.md
79
79
  files:
80
+ - ".bundle/config"
80
81
  - ".github/workflows/ruby.yml"
81
82
  - ".gitignore"
82
83
  - ".travis.yml"
@@ -113,7 +114,6 @@ files:
113
114
  - lib/dr/tools/gtk.rb
114
115
  - lib/dr/version.rb
115
116
  - lib/drain.rb
116
- - lib/drain/version.rb
117
117
  - test/helper.rb
118
118
  - test/test_converter.rb
119
119
  - test/test_core_ext.rb
@@ -130,7 +130,7 @@ licenses:
130
130
  - MIT
131
131
  metadata:
132
132
  yard.run: yri
133
- post_install_message:
133
+ post_install_message:
134
134
  rdoc_options: []
135
135
  require_paths:
136
136
  - lib
@@ -145,8 +145,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
145
145
  - !ruby/object:Gem::Version
146
146
  version: '0'
147
147
  requirements: []
148
- rubygems_version: 3.1.2
149
- signing_key:
148
+ rubygems_version: 3.1.4
149
+ signing_key:
150
150
  specification_version: 4
151
151
  summary: Use a drain for a dryer ruby!
152
152
  test_files: []
@@ -1,4 +0,0 @@
1
- module Drain
2
- # drain version
3
- VERSION = "0.1.0"
4
- end