rdoba 0.9.1 → 0.9.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -7
- data/.gitignore +4 -0
- data/.travis.yml +28 -0
- data/CHANGES.md +6 -0
- data/Gemfile +5 -0
- data/README.md +87 -108
- data/Rakefile +62 -54
- data/TODO +6 -0
- data/features/mixin.feature +85 -0
- data/features/step_definitions/mixin_steps.rb +305 -0
- data/features/support/env.rb +35 -145
- data/features/support/mixin_support.rb +17 -0
- data/html/.keep +0 -0
- 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 -68
- data/lib/rdoba/debug.rb +9 -3
- 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 +21 -0
- data/lib/rdoba/mixin/time.rb +17 -0
- data/lib/rdoba/mixin/try.rb +11 -0
- data/lib/rdoba/mixin/try_1_9_0.rb +9 -0
- data/lib/rdoba/mixin/wait_if.rb +27 -0
- data/lib/rdoba/mixin.rb +373 -52
- 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 +32 -22
- data/lib/rdoba/strings.rb +6 -144
- data/lib/rdoba/yaml.rb +20 -18
- data/lib/rdoba.rb +50 -47
- data/rdoba.gemspec +33 -26
- data/tddium.yml +11 -0
- metadata +184 -77
- data/features/bcd.feature +0 -29
- data/features/log.feature +0 -206
- data/features/step_definitions/bcd_steps.rb +0 -69
- data/features/step_definitions/log_steps.rb +0 -164
- data/lib/rdoba/log.rb +0 -248
- data/test/helper.rb +0 -18
- data/test/rdoba_test.rb.stub +0 -59
- data/test/test_rdoba.rb +0 -7
data/lib/rdoba/gem.rb
CHANGED
@@ -1,36 +1,40 @@
|
|
1
1
|
#!/usr/bin/ruby -KU
|
2
|
-
#
|
2
|
+
# frozen_string_literal: true
|
3
3
|
|
4
4
|
require 'rbconfig'
|
5
5
|
|
6
6
|
module Rdoba
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
File.join g.full_gem_path, 'share', 'settings.yaml'
|
12
|
-
end
|
7
|
+
def self.gemroot(gemname = nil, _path = '')
|
8
|
+
unless gem
|
9
|
+
raise 'Undefined gem name'
|
10
|
+
end
|
13
11
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
case host_os
|
18
|
-
when /(mswin|msys|mingw|cygwin|bccwin|wince|emc)/
|
19
|
-
plat = $1 == 'mswin' && 'native' || $1
|
20
|
-
out = `ver`.encode( 'US-ASCII',
|
21
|
-
:invalid => :replace, :undef => :replace )
|
22
|
-
if out =~ /\[.* (\d+)\.([\d\.]+)\]/
|
23
|
-
"windows-#{plat}-#{$1 == '5' && 'xp' || 'vista'}-#{$1}.#{$2}"
|
24
|
-
else
|
25
|
-
"windows-#{plat}" ; end
|
26
|
-
when /darwin|mac os/
|
27
|
-
'macosx'
|
28
|
-
when /linux/
|
29
|
-
'linux'
|
30
|
-
when /(solaris|bsd)/
|
31
|
-
"unix-#{$1}"
|
32
|
-
else
|
33
|
-
raise "unknown os: #{host_os.inspect}"
|
34
|
-
end)
|
35
|
-
end ; end
|
12
|
+
g = Gem::Specification.find_by_name(gemname)
|
13
|
+
File.join g.full_gem_path, 'share', 'settings.yaml'
|
14
|
+
end
|
36
15
|
|
16
|
+
def self.os
|
17
|
+
@@os ||=
|
18
|
+
begin
|
19
|
+
host_os = RbConfig::CONFIG['host_os']
|
20
|
+
case host_os
|
21
|
+
when /(mswin|msys|mingw|cygwin|bccwin|wince|emc)/
|
22
|
+
plat = Regexp.last_match(1) == 'mswin' && 'native' || Regexp.last_match(1)
|
23
|
+
out = `ver`.encode('US-ASCII', invalid: :replace, undef: :replace)
|
24
|
+
if out =~ /\[.* (\d+)\.([\d.]+)\]/
|
25
|
+
"windows-#{plat}-#{Regexp.last_match(1) == '5' && 'xp' || 'vista'}-#{Regexp.last_match(1)}.#{Regexp.last_match(2)}"
|
26
|
+
else
|
27
|
+
"windows-#{plat}"
|
28
|
+
end
|
29
|
+
when /darwin|mac os/
|
30
|
+
'macosx'
|
31
|
+
when /linux/
|
32
|
+
'linux'
|
33
|
+
when /(solaris|bsd)/
|
34
|
+
"unix-#{Regexp.last_match(1)}"
|
35
|
+
else
|
36
|
+
raise "unknown os: #{host_os.inspect}"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/lib/rdoba/hashorder.rb
CHANGED
@@ -1,35 +1,36 @@
|
|
1
1
|
#!/usr/bin/ruby
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
4
|
class Hash
|
4
5
|
attr_reader :order
|
5
6
|
|
6
7
|
class Each
|
7
8
|
General = 0
|
8
|
-
Pair
|
9
|
-
Key
|
10
|
-
Value
|
9
|
+
Pair = 1
|
10
|
+
Key = 2
|
11
|
+
Value = 3
|
11
12
|
end
|
12
13
|
|
13
|
-
private
|
14
|
+
private
|
14
15
|
|
15
16
|
def each_special(spec)
|
16
|
-
(@order |
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
17
|
+
(@order | keys).each do |key|
|
18
|
+
next unless has_key? key
|
19
|
+
|
20
|
+
case spec
|
21
|
+
when Hash::Each::General
|
22
|
+
yield key, self[key]
|
23
|
+
when Hash::Each::Pair
|
24
|
+
yield key, self[key]
|
25
|
+
when Hash::Each::Key
|
26
|
+
yield key
|
27
|
+
when Hash::Each::Value
|
28
|
+
yield self[key]
|
28
29
|
end
|
29
30
|
end
|
30
31
|
end
|
31
32
|
|
32
|
-
public
|
33
|
+
public
|
33
34
|
|
34
35
|
def order=(order)
|
35
36
|
return nil if order.class != Array
|
@@ -38,13 +39,14 @@ public
|
|
38
39
|
end
|
39
40
|
|
40
41
|
def disorder
|
41
|
-
@order = nil
|
42
|
+
@order = nil
|
43
|
+
self
|
42
44
|
end
|
43
45
|
|
44
|
-
alias
|
45
|
-
alias
|
46
|
-
alias
|
47
|
-
alias
|
46
|
+
alias __each__ each
|
47
|
+
alias __each_pair__ each_pair
|
48
|
+
alias __each_key__ each_key
|
49
|
+
alias __each_value__ each_value
|
48
50
|
|
49
51
|
def each(&block)
|
50
52
|
@order ? each_special(Hash::Each::General, &block) : __each__(&block)
|
@@ -61,6 +63,4 @@ public
|
|
61
63
|
def each_value(&block)
|
62
64
|
@order ? each_special(Hash::Each::Value, &block) : __each_value__(&block)
|
63
65
|
end
|
64
|
-
|
65
66
|
end
|
66
|
-
|
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
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Rdoba::Merge
|
4
|
+
TARGET = :Hash
|
5
|
+
|
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
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Rdoba::Mixin::Time
|
4
|
+
require 'ffi/stat'
|
5
|
+
|
6
|
+
def mtime(file)
|
7
|
+
FFI::Stat.stat(file)[:st_mtimespec].to_time
|
8
|
+
end
|
9
|
+
|
10
|
+
def atime(file)
|
11
|
+
FFI::Stat.stat(file)[:st_atimespec].to_time
|
12
|
+
end
|
13
|
+
|
14
|
+
def ctime(file)
|
15
|
+
FFI::Stat.stat(file)[:st_ctimespec].to_time
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'timeout'
|
4
|
+
|
5
|
+
module Rdoba::Mixin::Wait_ifKernel
|
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
|