drain 0.3.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +25 -0
- data/.travis.yml +7 -3
- data/ChangeLog.md +159 -2
- data/Gemfile +4 -1
- data/LICENSE.txt +1 -1
- data/README.md +14 -3
- data/Rakefile +15 -10
- data/drain.gemspec +1 -0
- data/gemspec.yml +3 -3
- data/lib/dr/base/delegate.rb +28 -0
- data/lib/dr/base/graph.rb +26 -9
- data/lib/dr/base/uri.rb +224 -192
- data/lib/dr/base/utils.rb +39 -8
- data/lib/dr/parse/simple_keywords.rb +1 -1
- data/lib/dr/parse/time_parse.rb +29 -23
- data/lib/dr/ruby_ext/core_modules.rb +5 -3
- data/lib/dr/version.rb +1 -1
- data/test/helper.rb +12 -2
- data/test/test_converter.rb +7 -7
- data/test/test_core_ext.rb +24 -24
- data/test/test_date_parse.rb +8 -4
- data/test/test_graph.rb +26 -26
- data/test/test_meta.rb +3 -3
- data/test/test_simple_keywords.rb +6 -6
- data/test/test_simple_parser.rb +9 -9
- data/test/test_time_parse.rb +43 -0
- data/test/test_uri.rb +35 -0
- metadata +20 -16
data/test/test_meta.rb
CHANGED
@@ -49,17 +49,17 @@ describe DR::Meta do
|
|
49
49
|
# end
|
50
50
|
|
51
51
|
it "Can show all ancestors" do
|
52
|
-
DR::Meta.all_ancestors("foo").include?(String.singleton_class).must_equal(true)
|
52
|
+
_(DR::Meta.all_ancestors("foo").include?(String.singleton_class)).must_equal(true)
|
53
53
|
end
|
54
54
|
|
55
55
|
it "Can generate bound methods" do
|
56
56
|
m=DR::Meta.get_bound_method("foo", :bar) do |x|
|
57
57
|
self+x
|
58
58
|
end
|
59
|
-
m.call("bar").must_equal("foobar")
|
59
|
+
_(m.call("bar")).must_equal("foobar")
|
60
60
|
end
|
61
61
|
|
62
62
|
it "Can apply unbound methods" do
|
63
|
-
DR::Meta.apply(method: String.instance_method(:length), to: "foo").must_equal(3)
|
63
|
+
_(DR::Meta.apply(method: String.instance_method(:length), to: "foo")).must_equal(3)
|
64
64
|
end
|
65
65
|
end
|
@@ -10,27 +10,27 @@ describe DR::SimpleKeywordsParser do
|
|
10
10
|
end
|
11
11
|
|
12
12
|
it "Can parse keywords" do
|
13
|
-
@parser.parse("FOO(ploum, plam)").must_equal 'FOO: ["ploum", "plam"]'
|
13
|
+
_(@parser.parse("FOO(ploum, plam)")).must_equal 'FOO: ["ploum", "plam"]'
|
14
14
|
end
|
15
15
|
|
16
16
|
it "Can preserver spaces" do
|
17
|
-
@parser.parse("FOO( ploum , plam )", space: true).must_equal "FOO: [\" ploum \", \" plam \"]"
|
17
|
+
_(@parser.parse("FOO( ploum , plam )", space: true)).must_equal "FOO: [\" ploum \", \" plam \"]"
|
18
18
|
end
|
19
19
|
|
20
20
|
it "Can change delimiters" do
|
21
|
-
@parser.parse("FOO[ ploum , plam ]", delims: '[]').must_equal "FOO: [\"ploum\", \"plam\"]"
|
21
|
+
_(@parser.parse("FOO[ ploum , plam ]", delims: '[]')).must_equal "FOO: [\"ploum\", \"plam\"]"
|
22
22
|
end
|
23
23
|
|
24
24
|
it "Can have a one caracter delimiter" do
|
25
|
-
@parser.parse("FOO! ploum , plam !", delims: '!').must_equal "FOO: [\"ploum\", \"plam\"]"
|
25
|
+
_(@parser.parse("FOO! ploum , plam !", delims: '!')).must_equal "FOO: [\"ploum\", \"plam\"]"
|
26
26
|
end
|
27
27
|
|
28
28
|
it "Can parse keywords inside keywords" do
|
29
|
-
@parser.parse("FOO(ploum, BAR( foo, bar ))").must_equal "FOO: [\"ploum\", \"BAR: [\\\"foo\\\"\", \"\\\"bar\\\"]\"]"
|
29
|
+
_(@parser.parse("FOO(ploum, BAR( foo, bar ))")).must_equal "FOO: [\"ploum\", \"BAR: [\\\"foo\\\"\", \"\\\"bar\\\"]\"]"
|
30
30
|
end
|
31
31
|
|
32
32
|
it "Can add a keyword" do
|
33
33
|
@parser.keyword("PLOUM") { |a,b| a.to_i+b.to_i}
|
34
|
-
@parser.parse("Hello PLOUM(2,3)").must_equal 'Hello 5'
|
34
|
+
_(@parser.parse("Hello PLOUM(2,3)")).must_equal 'Hello 5'
|
35
35
|
end
|
36
36
|
end
|
data/test/test_simple_parser.rb
CHANGED
@@ -4,34 +4,34 @@ require 'dr/parse/simple_parser'
|
|
4
4
|
describe DR::SimpleParser do
|
5
5
|
describe "parse_namevalue" do
|
6
6
|
it "parses a simple name value" do
|
7
|
-
DR::SimpleParser.parse_namevalue("foo:bar").must_equal([:foo,"bar"])
|
7
|
+
_(DR::SimpleParser.parse_namevalue("foo:bar")).must_equal([:foo,"bar"])
|
8
8
|
end
|
9
9
|
it "can let the name be a string" do
|
10
|
-
DR::SimpleParser.parse_namevalue("foo:bar",symbolize:false).must_equal(["foo","bar"])
|
10
|
+
_(DR::SimpleParser.parse_namevalue("foo:bar",symbolize:false)).must_equal(["foo","bar"])
|
11
11
|
end
|
12
12
|
it "only splits on the first ':'" do
|
13
|
-
DR::SimpleParser.parse_namevalue("foo:bar:baz").must_equal([:foo,"bar:baz"])
|
13
|
+
_(DR::SimpleParser.parse_namevalue("foo:bar:baz")).must_equal([:foo,"bar:baz"])
|
14
14
|
end
|
15
15
|
it "can change the separation" do
|
16
|
-
DR::SimpleParser.parse_namevalue("foo:bar!baz", sep: "!",symbolize:false).must_equal(["foo:bar","baz"])
|
16
|
+
_(DR::SimpleParser.parse_namevalue("foo:bar!baz", sep: "!",symbolize:false)).must_equal(["foo:bar","baz"])
|
17
17
|
end
|
18
18
|
it "can set a default" do
|
19
|
-
DR::SimpleParser.parse_namevalue("foo", default: 0).must_equal([:foo,0])
|
19
|
+
_(DR::SimpleParser.parse_namevalue("foo", default: 0)).must_equal([:foo,0])
|
20
20
|
end
|
21
21
|
it "If the default is true then support 'no-foo'" do
|
22
|
-
DR::SimpleParser.parse_namevalue("no-foo", default: true).must_equal([:foo,false])
|
22
|
+
_(DR::SimpleParser.parse_namevalue("no-foo", default: true)).must_equal([:foo,false])
|
23
23
|
end
|
24
24
|
it "can set the default to true" do
|
25
|
-
DR::SimpleParser.parse_namevalue("foo", default: true, symbolize:false).must_equal(["foo",true])
|
25
|
+
_(DR::SimpleParser.parse_namevalue("foo", default: true, symbolize:false)).must_equal(["foo",true])
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
29
|
describe "parse_strings" do
|
30
30
|
it "can parse several name values" do
|
31
|
-
DR::SimpleParser.parse_string("foo:bar,ploum:plim")[:values].must_equal({foo: "bar", ploum: "plim"})
|
31
|
+
_(DR::SimpleParser.parse_string("foo:bar,ploum:plim")[:values]).must_equal({foo: "bar", ploum: "plim"})
|
32
32
|
end
|
33
33
|
it "can handle options" do
|
34
|
-
DR::SimpleParser.parse_string("name1:value1!option1=ploum!option2=plam!option3,name2:value2!!globalopt1=foo,globalopt2=bar").must_equal({
|
34
|
+
_(DR::SimpleParser.parse_string("name1:value1!option1=ploum!option2=plam!option3,name2:value2!!globalopt1=foo,globalopt2=bar")).must_equal({
|
35
35
|
values: {name1: "value1", name2: "value2"},
|
36
36
|
local_opts: {name1: {option1:"ploum",option2:"plam",option3:true}, name2: {}},
|
37
37
|
global_opts: {globalopt1: "foo", globalopt2: "bar"},
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'helper'
|
2
|
+
require 'dr/parse/time_parse'
|
3
|
+
|
4
|
+
describe DR::TimeParse do
|
5
|
+
before do
|
6
|
+
@tz=ENV['TZ']
|
7
|
+
ENV['TZ']='GMT'
|
8
|
+
class << Time
|
9
|
+
alias _original_now now
|
10
|
+
def now
|
11
|
+
Time.new(2000)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
after do
|
16
|
+
ENV['TZ']=@tz
|
17
|
+
class << Time
|
18
|
+
alias now _original_now
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
it "Can parse a range" do
|
23
|
+
_(DR::TimeParse.parse("+100..tomorrow")).must_equal(
|
24
|
+
Time.parse("2000-01-01 00:01:40")..Time.parse("2000-01-02 12:00:00")
|
25
|
+
)
|
26
|
+
_(DR::TimeParse.parse("now..in seven days")).must_equal(
|
27
|
+
Time.parse("2000-01-01 00:00:00")..Time.parse("2000-01-08 00:00:00")
|
28
|
+
)
|
29
|
+
end
|
30
|
+
|
31
|
+
it "Can parse a date" do
|
32
|
+
_(DR::TimeParse.parse("today")).must_equal(Time.parse("2000-01-01-12:00:00"))
|
33
|
+
end
|
34
|
+
|
35
|
+
it "Can put a date in a range" do
|
36
|
+
_(DR::TimeParse.parse("today", range: true)).must_equal(
|
37
|
+
Time.parse("2000-01-01-00:00:00")..Time.parse("2000-01-02-00:00:00")
|
38
|
+
)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
#with active_support: DR::TimeParse.parse("-3 years 2 minutes")
|
43
|
+
#=> 2011-08-22 20:01:34 +0200
|
data/test/test_uri.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'helper'
|
2
|
+
require 'dr/base/uri'
|
3
|
+
|
4
|
+
describe DR::URI::Wrapper do
|
5
|
+
before do
|
6
|
+
@uri=DR::URI::Wrapper.new(DR::URI::Escape.escape("http://ploum:secret@plam:443/foo bar"))
|
7
|
+
end
|
8
|
+
it "Wraps an uri element" do
|
9
|
+
_(@uri.scheme).must_equal "http"
|
10
|
+
end
|
11
|
+
it "Auto escapes attribute" do
|
12
|
+
_(@uri.path).must_equal "/foo bar"
|
13
|
+
end
|
14
|
+
it "Auto escape setting elements" do
|
15
|
+
@uri.user="ploum plam"
|
16
|
+
_(@uri.user).must_equal "ploum plam"
|
17
|
+
end
|
18
|
+
it "Can convert to a hash" do
|
19
|
+
_(@uri.to_h[:user]).must_equal("ploum")
|
20
|
+
end
|
21
|
+
it "Can convert to json" do
|
22
|
+
require 'json'
|
23
|
+
_(@uri.to_json).must_equal("{\"uri\":\"http://ploum:secret@plam:443/foo%20bar\",\"scheme\":\"http\",\"userinfo\":\"ploum:secret\",\"host\":\"plam\",\"port\":443,\"path\":\"/foo bar\",\"user\":\"ploum\",\"password\":\"secret\"}")
|
24
|
+
end
|
25
|
+
it "Can remove password" do
|
26
|
+
_(@uri.to_public).must_equal("http://ploum@plam:443/foo%20bar")
|
27
|
+
end
|
28
|
+
it "Can be merged" do
|
29
|
+
_(@uri.soft_merge("foo://plim@").to_s).must_equal("foo://plim:secret@plam:443/foo%20bar")
|
30
|
+
end
|
31
|
+
it "Can be reverse merged" do
|
32
|
+
_(DR::URI::Wrapper.parse("//user@server").reverse_merge(@uri).to_s).must_equal("http://user:secret@server:443/foo%20bar")
|
33
|
+
end
|
34
|
+
end
|
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.
|
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:
|
11
|
+
date: 2020-10-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|
@@ -28,47 +28,47 @@ dependencies:
|
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '10'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '10'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: chronic
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '0.
|
47
|
+
version: '0.10'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '0.
|
54
|
+
version: '0.10'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: chronic_duration
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '0.
|
61
|
+
version: '0.10'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '0.
|
68
|
+
version: '0.10'
|
69
69
|
description: 'Drain is a small set of libraries that I use in my other gems.
|
70
70
|
|
71
|
-
'
|
71
|
+
'
|
72
72
|
email: Damien.Olivier.Robert+gems@gmail.com
|
73
73
|
executables: []
|
74
74
|
extensions: []
|
@@ -77,6 +77,8 @@ extra_rdoc_files:
|
|
77
77
|
- LICENSE.txt
|
78
78
|
- README.md
|
79
79
|
files:
|
80
|
+
- ".bundle/config"
|
81
|
+
- ".github/workflows/ruby.yml"
|
80
82
|
- ".gitignore"
|
81
83
|
- ".travis.yml"
|
82
84
|
- ".yardopts"
|
@@ -91,6 +93,7 @@ files:
|
|
91
93
|
- lib/dr/base.rb
|
92
94
|
- lib/dr/base/bool.rb
|
93
95
|
- lib/dr/base/converter.rb
|
96
|
+
- lib/dr/base/delegate.rb
|
94
97
|
- lib/dr/base/encoding.rb
|
95
98
|
- lib/dr/base/eruby.rb
|
96
99
|
- lib/dr/base/functional.rb
|
@@ -120,12 +123,14 @@ files:
|
|
120
123
|
- test/test_meta.rb
|
121
124
|
- test/test_simple_keywords.rb
|
122
125
|
- test/test_simple_parser.rb
|
126
|
+
- test/test_time_parse.rb
|
127
|
+
- test/test_uri.rb
|
123
128
|
homepage: https://github.com/DamienRobert/drain#readme
|
124
129
|
licenses:
|
125
130
|
- MIT
|
126
131
|
metadata:
|
127
132
|
yard.run: yri
|
128
|
-
post_install_message:
|
133
|
+
post_install_message:
|
129
134
|
rdoc_options: []
|
130
135
|
require_paths:
|
131
136
|
- lib
|
@@ -140,9 +145,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
140
145
|
- !ruby/object:Gem::Version
|
141
146
|
version: '0'
|
142
147
|
requirements: []
|
143
|
-
|
144
|
-
|
145
|
-
signing_key:
|
148
|
+
rubygems_version: 3.1.4
|
149
|
+
signing_key:
|
146
150
|
specification_version: 4
|
147
151
|
summary: Use a drain for a dryer ruby!
|
148
152
|
test_files: []
|