rdoba 0.9.3 → 0.9.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/Gemfile +4 -4
- data/README.md +21 -27
- data/Rakefile +21 -19
- data/features/step_definitions/mixin_steps.rb +237 -198
- data/features/support/env.rb +26 -160
- data/features/support/mixin_support.rb +13 -9
- data/lib/rdoba/_version_.rb +3 -1
- data/lib/rdoba/a.rb +44 -42
- data/lib/rdoba/bcd.rb +43 -26
- data/lib/rdoba/blank.rb +14 -0
- data/lib/rdoba/combinations.rb +17 -15
- data/lib/rdoba/common.rb +53 -53
- data/lib/rdoba/debug.rb +7 -5
- data/lib/rdoba/deploy.rb +55 -50
- data/lib/rdoba/dup.rb +31 -31
- data/lib/rdoba/fe.rb +6 -5
- data/lib/rdoba/gem.rb +33 -29
- data/lib/rdoba/hashorder.rb +24 -24
- data/lib/rdoba/io.rb +81 -74
- data/lib/rdoba/merge.rb +16 -16
- data/lib/rdoba/mixin/time.rb +13 -7
- data/lib/rdoba/mixin/try.rb +10 -5
- data/lib/rdoba/mixin/try_1_9_0.rb +8 -3
- data/lib/rdoba/mixin/wait_if.rb +24 -18
- data/lib/rdoba/mixin.rb +363 -306
- data/lib/rdoba/numeric.rb +19 -17
- data/lib/rdoba/os.rb +127 -0
- data/lib/rdoba/re.rb +4 -4
- data/lib/rdoba/require.rb +24 -19
- data/lib/rdoba/roman.rb +47 -35
- data/lib/rdoba/strings.rb +5 -6
- data/lib/rdoba/yaml.rb +20 -18
- data/lib/rdoba.rb +53 -44
- data/rdoba.gemspec +10 -9
- metadata +44 -46
- data/features/log.feature +0 -277
- data/features/step_definitions/log_steps.rb +0 -200
- data/features/support/fulltest_as_log.rb.in +0 -143
- data/features/support/fulltest_as_self.rb.in +0 -144
- data/lib/rdoba/log.rb +0 -419
data/lib/rdoba/io.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
#!/usr/bin/ruby -KU
|
2
|
-
#
|
2
|
+
# frozen_string_literal: true
|
3
3
|
|
4
4
|
require 'strscan'
|
5
5
|
require 'rdoba/re'
|
@@ -7,7 +7,7 @@ require 'rdoba/roman'
|
|
7
7
|
require 'rdoba/numeric'
|
8
8
|
|
9
9
|
module Kernel
|
10
|
-
alias
|
10
|
+
alias __sprintf__ sprintf
|
11
11
|
def sprintf(format, *args)
|
12
12
|
nargs = []
|
13
13
|
nformat = ''
|
@@ -15,26 +15,31 @@ module Kernel
|
|
15
15
|
fmt = format.split('%')
|
16
16
|
nformat = fmt.shift
|
17
17
|
|
18
|
-
|
18
|
+
until fmt.empty?
|
19
19
|
part = fmt.shift
|
20
|
-
part
|
21
|
-
if part =~ /([0-9 #+\-*.]*)([bcdEefGgiopsuXxP])(.*)/ and
|
22
|
-
keys =
|
23
|
-
str =
|
24
|
-
if keys =~ /(-)?([0-9*]*)\.?([0-9
|
20
|
+
part ||= '%' + fmt.shift
|
21
|
+
if part =~ /([0-9 #+\-*.]*)([bcdEefGgiopsuXxP])(.*)/ and Regexp.last_match(2) == 'P'
|
22
|
+
keys = Regexp.last_match(1) || ''
|
23
|
+
str = Regexp.last_match(3) || ''
|
24
|
+
if keys =~ /(-)?([0-9*]*)\.?([0-9*]*)(\+?)/
|
25
25
|
value = args.shift
|
26
|
-
indent = ' ' * (
|
27
|
-
plain =
|
28
|
-
|
29
|
-
|
30
|
-
|
26
|
+
indent = ' ' * (Regexp.last_match(2) == '*' ? args.shift : Regexp.last_match(2)).to_i
|
27
|
+
plain =
|
28
|
+
value &&
|
29
|
+
value.to_p(
|
30
|
+
padding:
|
31
|
+
(Regexp.last_match(3) == '*' ? args.shift : Regexp.last_match(3).empty? ? 1 : Regexp.last_match(3))
|
32
|
+
.to_i,
|
33
|
+
be: Regexp.last_match(4).empty? ? nil : true
|
34
|
+
) || ''
|
35
|
+
nformat += (Regexp.last_match(1) ? plain + indent : indent + plain) + str
|
31
36
|
else
|
32
37
|
nformat += '%' + keys + 'c' + str
|
33
38
|
nargs.push args.shift
|
34
39
|
end
|
35
40
|
else
|
36
41
|
nformat += '%' + part
|
37
|
-
l =
|
42
|
+
l = Regexp.last_match(1) =~ /\*/ ? 2 : 1
|
38
43
|
while l > 0
|
39
44
|
nargs.push args.shift
|
40
45
|
l -= 1
|
@@ -43,57 +48,59 @@ module Kernel
|
|
43
48
|
end
|
44
49
|
__sprintf__(nformat, *nargs).to_p
|
45
50
|
end
|
46
|
-
|
47
51
|
end
|
48
52
|
|
49
53
|
class String
|
50
54
|
def scanf_re(format)
|
51
|
-
fss = StringScanner.new(format) # TODO remove scanner in favor of match
|
55
|
+
fss = StringScanner.new(format) # TODO: remove scanner in favor of match
|
52
56
|
nformat = ''
|
53
57
|
|
54
58
|
pos = 0
|
55
59
|
argfs = []
|
56
60
|
while fss.scan_until(/%([0-9 #+\-*]*)(?:\.([0-9]+)(\+)?)?([bcdefgiosuxr])/)
|
57
|
-
argfs << [
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
61
|
+
argfs << [fss[1], fss[2], fss[3], fss[4]]
|
62
|
+
|
63
|
+
# TODO add performing the special case in fss[1]
|
64
|
+
nformat +=
|
65
|
+
fss.pre_match[pos..-1].to_res +
|
66
|
+
case fss[4]
|
67
|
+
when 'x'
|
68
|
+
'(?:0[xX])?([a-fA-F0-9]+)'
|
69
|
+
when 'i'
|
70
|
+
'([+\-]?[0-9]+)'
|
71
|
+
when 'u'
|
72
|
+
'([0-9]+)'
|
73
|
+
when 'e'
|
74
|
+
'([+\-]?[0-9]+[eE][+\-]?[0-9]+)'
|
75
|
+
when 'f'
|
76
|
+
'([+\-]?[0-9]+\.[0-9]*)'
|
77
|
+
when 'g'
|
78
|
+
'([+\-]?[0-9]+(?:[eE][+\-]?[0-9]+|\.[0-9]*))'
|
79
|
+
when 'c'
|
80
|
+
fss[2] ? "(.{1,#{fss[2]}})" : '(.)'
|
81
|
+
when 'b'
|
82
|
+
'([01]+)b?'
|
83
|
+
when 'o'
|
84
|
+
'0([0-9]+)'
|
85
|
+
when 'd'
|
86
|
+
'([+\-]?(?:0X)?[A-F0-9.+]+)'
|
87
|
+
when 's'
|
88
|
+
'(.+)'
|
89
|
+
when 'r'
|
90
|
+
'([IVXLCDMivxlcdm]+)'
|
91
|
+
end
|
85
92
|
|
86
93
|
pos = fss.pos
|
87
94
|
end
|
88
95
|
|
89
96
|
nformat += fss.rest
|
90
97
|
|
91
|
-
[
|
98
|
+
[/#{nformat}/, argfs]
|
92
99
|
end
|
93
100
|
|
94
|
-
(alias
|
101
|
+
(alias __scanf__ scanf) if instance_methods(false).include?(:scanf)
|
95
102
|
def scanf(format, &block)
|
96
|
-
|
103
|
+
re, argfs = scanf_re(format)
|
97
104
|
|
98
105
|
ss = StringScanner.new(self)
|
99
106
|
res = []
|
@@ -102,29 +109,32 @@ class String
|
|
102
109
|
argfs.each_index do |i|
|
103
110
|
argf = argfs[i]
|
104
111
|
value = ss[i + 1]
|
105
|
-
rline <<
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
112
|
+
rline <<
|
113
|
+
case argf[3]
|
114
|
+
when 'x'
|
115
|
+
value.to_i(16)
|
116
|
+
when /[diu]/
|
117
|
+
value.to_i
|
118
|
+
when /[efg]/
|
119
|
+
value.to_f
|
120
|
+
when 'c'
|
121
|
+
argf[2] ? value.to_i(:be) : value.to_i
|
122
|
+
when 'b'
|
123
|
+
value.to_i(2)
|
124
|
+
when 'o'
|
125
|
+
value.to_i(8)
|
126
|
+
when 's'
|
127
|
+
value
|
128
|
+
when 'r'
|
129
|
+
value.rom
|
130
|
+
end
|
123
131
|
end
|
124
132
|
|
125
|
-
if
|
133
|
+
if block
|
126
134
|
pass = []
|
127
|
-
(1..block.arity).each do |i|
|
135
|
+
(1..block.arity).each do |i|
|
136
|
+
pass << "rline[#{i}]"
|
137
|
+
end
|
128
138
|
eval "yield(#{pass.join(', ')})"
|
129
139
|
end
|
130
140
|
|
@@ -144,17 +154,14 @@ class String
|
|
144
154
|
ostr[0...ss.pre_match.size - pos] = ss.pre_match[pos..-1]
|
145
155
|
pos = ss.pos
|
146
156
|
|
147
|
-
|
148
|
-
res = ostr
|
149
|
-
pos += 1
|
150
|
-
ostr = ''
|
151
|
-
end
|
157
|
+
next unless ss.post_match[0] == "\n"[0]
|
152
158
|
|
159
|
+
res = ostr
|
160
|
+
pos += 1
|
161
|
+
ostr = ''
|
153
162
|
end
|
154
163
|
|
155
164
|
ostr[0...ss.rest.size] = ss.rest
|
156
165
|
res + ostr
|
157
166
|
end
|
158
167
|
end
|
159
|
-
|
160
|
-
|
data/lib/rdoba/merge.rb
CHANGED
@@ -1,21 +1,21 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Rdoba::Merge
|
4
|
-
|
4
|
+
TARGET = :Hash
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
end
|
6
|
+
def deep_merge(source, dest)
|
7
|
+
dup = dest.dup
|
8
|
+
source.each do |key, value|
|
9
|
+
newvalue = dup.delete key
|
10
|
+
case newvalue
|
11
|
+
when Hash
|
12
|
+
value.deep_merge newvalue
|
13
|
+
when Array
|
14
|
+
value |= newvalue
|
15
|
+
when NilClass
|
16
|
+
else
|
17
|
+
raise
|
19
18
|
end
|
20
|
-
|
19
|
+
end
|
20
|
+
end
|
21
21
|
end
|
data/lib/rdoba/mixin/time.rb
CHANGED
@@ -1,11 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Rdoba::Mixin::Time
|
2
|
-
|
4
|
+
require 'ffi/stat'
|
3
5
|
|
4
|
-
|
5
|
-
|
6
|
+
def mtime(file)
|
7
|
+
FFI::Stat.stat(file)[:st_mtimespec].to_time
|
8
|
+
end
|
6
9
|
|
7
|
-
|
8
|
-
|
10
|
+
def atime(file)
|
11
|
+
FFI::Stat.stat(file)[:st_atimespec].to_time
|
12
|
+
end
|
9
13
|
|
10
|
-
|
11
|
-
|
14
|
+
def ctime(file)
|
15
|
+
FFI::Stat.stat(file)[:st_ctimespec].to_time
|
16
|
+
end
|
17
|
+
end
|
data/lib/rdoba/mixin/try.rb
CHANGED
@@ -1,6 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Rdoba::Mixin::TryObject
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
def try(method, *args, default: nil)
|
5
|
+
if respond_to?(method)
|
6
|
+
send(method, *args)
|
7
|
+
else
|
8
|
+
default
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
data/lib/rdoba/mixin/wait_if.rb
CHANGED
@@ -1,21 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'timeout'
|
2
4
|
|
3
5
|
module Rdoba::Mixin::Wait_ifKernel
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
6
|
+
##
|
7
|
+
# +wait_if+ waits for +timeout+ second to the condition passed via block,
|
8
|
+
# and in case if it failed, returns false, otherwise true. +timeout+ can
|
9
|
+
# be a float or integer number of seconds, but if passed 0 or nil it waits
|
10
|
+
# forever. Default value is 6 seconds. Example:
|
11
|
+
#
|
12
|
+
# wait_if(5) { sleep 2; true } # => true
|
13
|
+
# wait_if(5) { sleep 10; true } # => false
|
14
|
+
#
|
15
|
+
def wait_if(timeout = 6)
|
16
|
+
begin
|
17
|
+
Timeout.timeout(timeout) do
|
18
|
+
while yield()
|
19
|
+
sleep(0.1)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
true
|
23
|
+
rescue Timeout::Error
|
24
|
+
false
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|