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/features/support/env.rb
CHANGED
@@ -1,8 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'rdoba'
|
2
4
|
require 'tmpdir'
|
3
5
|
require 'open3'
|
4
6
|
require 'coveralls'
|
5
|
-
require "codeclimate-test-reporter"
|
6
7
|
require 'simplecov'
|
7
8
|
require 'rspec/expectations'
|
8
9
|
|
@@ -10,176 +11,41 @@ require 'rspec/expectations'
|
|
10
11
|
#
|
11
12
|
#
|
12
13
|
Coveralls.wear!
|
13
|
-
CodeClimate::TestReporter.start
|
14
14
|
SimpleCov.start
|
15
15
|
##############################################
|
16
16
|
|
17
|
-
RdobaSimSimpleHead
|
18
|
-
#!/usr/bin/env ruby
|
19
|
-
|
20
|
-
require 'rdoba'
|
21
|
-
HEAD
|
22
|
-
|
23
|
-
RdobaCodeClassDeclaration=<<HEAD
|
24
|
-
class Cls
|
25
|
-
def initialize
|
26
|
-
log > {:variable=>"value"}
|
27
|
-
end
|
28
|
-
end
|
17
|
+
RdobaSimSimpleHead = <<~HEAD
|
18
|
+
#!/usr/bin/env ruby
|
19
|
+
|
20
|
+
require 'rdoba'
|
29
21
|
HEAD
|
30
22
|
|
31
|
-
RdobaSimClsHead
|
32
|
-
#!/usr/bin/env ruby
|
33
|
-
|
34
|
-
require 'rdoba'
|
35
|
-
class Cls
|
23
|
+
RdobaSimClsHead = <<~HEAD
|
24
|
+
#!/usr/bin/env ruby
|
25
|
+
|
26
|
+
require 'rdoba'
|
27
|
+
class Cls
|
36
28
|
HEAD
|
37
29
|
|
38
|
-
def format
|
30
|
+
def format(str)
|
39
31
|
puts str
|
40
|
-
|
32
|
+
' ' * @deep + str + "\n"
|
33
|
+
end
|
41
34
|
|
42
35
|
def store
|
43
|
-
file = @inithead + @init + @echo + (
|
36
|
+
file = @inithead + @init + @echo + ("end\n" * @deep)
|
44
37
|
puts file
|
45
|
-
File.open(
|
46
|
-
f.puts file
|
47
|
-
|
48
|
-
def match_keywords keystr
|
49
|
-
keys = ( keystr || '' ).split( /[,:\s]/ ).map do |k|
|
50
|
-
[ :basic, :extended, :enter, :leave, :compat, :timestamp, :pid,
|
51
|
-
:function_name, :function_line, :function ].include?( k.to_sym ) && k.to_sym || nil
|
52
|
-
end.compact ; end
|
53
|
-
|
54
|
-
def rdoba_sim sub, cmd, *args
|
55
|
-
echo = nil
|
56
|
-
case sub
|
57
|
-
when :log, :debug
|
58
|
-
case cmd
|
59
|
-
when :init
|
60
|
-
$tmpdir ||= Dir.mktmpdir
|
61
|
-
@tmpfile ||= File.join( $tmpdir, 'tmp.log' )
|
62
|
-
|
63
|
-
if args[ 1 ] == 'class'
|
64
|
-
@deep = 1
|
65
|
-
@inithead = RdobaSimClsHead
|
66
|
-
else
|
67
|
-
@deep = 0
|
68
|
-
@inithead = RdobaSimSimpleHead ; end
|
69
|
-
@echo = ''
|
70
|
-
@init = ''
|
71
|
-
puts @inithead
|
72
|
-
|
73
|
-
when :apply
|
74
|
-
opts = match_keywords args[ 1 ]
|
75
|
-
# opts = opts.size > 2 && opts || opts.size > 0 && opts[ 1 ] || nil
|
76
|
-
param = case args[ 0 ]
|
77
|
-
when 'io'
|
78
|
-
{ :io => "File.new( File.join( '#{@tmpfile}' ), 'w+' )", :functions => :basic }
|
79
|
-
when 'as'
|
80
|
-
{ :as => ":self", :functions => :basic }
|
81
|
-
when 'in'
|
82
|
-
{ :in => "Cls", :functions => :basic }
|
83
|
-
# when /in.*as/
|
84
|
-
# { :in => "Cls", :as => args[ 2 ].to_sym, :functions => :basic }
|
85
|
-
when 'prefix'
|
86
|
-
# basic|extended|enter|leave|compat
|
87
|
-
{ args[ 0 ].to_sym => opts, :functions => :basic }
|
88
|
-
when 'functions'
|
89
|
-
{ args[ 0 ].to_sym => opts }
|
90
|
-
else
|
91
|
-
{ :functions => :basic }
|
92
|
-
end
|
93
|
-
|
94
|
-
if args[ 2 ]
|
95
|
-
param.merge!( :as => args[ 2 ].to_sym ) ; end
|
96
|
-
|
97
|
-
param = "{" + ( param ).to_a.map do |v|
|
98
|
-
"#{v[ 0 ].inspect} => #{v[ 1 ].is_a?( String ) &&
|
99
|
-
v[ 1 ] || v[ 1 ].inspect}" end.join(',') + "}"
|
100
|
-
|
101
|
-
@echo << " " * @deep + "rdoba :#{sub} => #{param}\n"
|
102
|
-
|
103
|
-
when :func
|
104
|
-
call = case args[ 0 ]
|
105
|
-
when 'keyword'
|
106
|
-
'self'
|
107
|
-
when 'invalid keyword'
|
108
|
-
'errlog'
|
109
|
-
when /^db/
|
110
|
-
@echo << "self.dbgl = 0xff\n"
|
111
|
-
args[ 0 ]
|
112
|
-
else
|
113
|
-
( args[ 0 ] || :log ).to_sym
|
114
|
-
end
|
115
|
-
|
116
|
-
sep = ( args[ 1 ] == :e ) && '.' || ' '
|
117
|
-
param = []
|
118
|
-
args[ 2..-1 ].each do |arg|
|
119
|
-
case arg
|
120
|
-
when NilClass
|
121
|
-
when Symbol
|
122
|
-
param << " #{arg}"
|
123
|
-
else
|
124
|
-
param << " #{arg.inspect}" ; end ; end
|
125
|
-
str = "#{call}#{sep}#{args[ 1 ]}#{param.join(',')}"
|
126
|
-
echo = format str
|
127
|
-
@echo << echo
|
128
|
-
|
129
|
-
when :close
|
130
|
-
while @deep > 0
|
131
|
-
@deep -= 1
|
132
|
-
@echo << ( format "end" ) ; end
|
133
|
-
|
134
|
-
when :declare
|
135
|
-
@echo << ( format RdobaCodeClassDeclaration )
|
136
|
-
|
137
|
-
when :create
|
138
|
-
@echo << ( format "Cls.new" )
|
139
|
-
|
140
|
-
when :call
|
141
|
-
@echo << ( format "Cls.singleton" )
|
142
|
-
|
143
|
-
when :def
|
144
|
-
if @inithead == RdobaSimClsHead
|
145
|
-
@deep = 1
|
146
|
-
else
|
147
|
-
@deep = 0 ; end
|
148
|
-
echo = case args[ 0 ]
|
149
|
-
when :init
|
150
|
-
@deep += 1
|
151
|
-
format 'def initialize'
|
152
|
-
when :single
|
153
|
-
@deep += 1
|
154
|
-
format 'def self.singleton'
|
155
|
-
else;
|
156
|
-
'' ; end
|
157
|
-
@echo << echo
|
158
|
-
|
159
|
-
when :exec
|
160
|
-
if !@echo.empty?
|
161
|
-
store
|
162
|
-
puts '-' * 15
|
163
|
-
|
164
|
-
File.chmod 0755, @tmpfile
|
165
|
-
Open3.popen3( @tmpfile ) do |stdin, stdout, stderr, wait_thr|
|
166
|
-
@out = stdout.read
|
167
|
-
@err = stderr.read
|
168
|
-
end
|
169
|
-
@echo = ''
|
170
|
-
end
|
171
|
-
res = case args[ 0 ]
|
172
|
-
when :file
|
173
|
-
File.new( @tmpfile, 'r' ).read
|
174
|
-
when :stdout
|
175
|
-
@out
|
176
|
-
when :stderr
|
177
|
-
@err;
|
178
|
-
else return; end
|
179
|
-
puts res
|
180
|
-
res
|
181
|
-
end
|
38
|
+
File.open(@tmpfile, 'w+') do |f|
|
39
|
+
f.puts file
|
182
40
|
end
|
183
41
|
end
|
184
42
|
|
185
|
-
|
43
|
+
def match_keywords(keystr)
|
44
|
+
keys =
|
45
|
+
(keystr || '').split(/[,:\s]/).map do |k|
|
46
|
+
%i[basic extended enter leave compat timestamp pid function_name function_line function].include?(k.to_sym) &&
|
47
|
+
k.to_sym || nil
|
48
|
+
end.compact
|
49
|
+
end
|
50
|
+
|
51
|
+
at_exit { $tmpdir && (FileUtils.remove_entry_secure $tmpdir) }
|
@@ -1,13 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module MixinSupport
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
end.join[ 0...count ] ; end
|
4
|
+
def random_string(count)
|
5
|
+
Random.new.bytes((count + 1) / 2).split('').map do |b| b.ord.to_s(16)end.join[0...count]
|
6
|
+
end
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
8
|
+
def tmpfile
|
9
|
+
filename = File.join(Dir.mktmpdir, random_string(20))
|
10
|
+
File.open(filename, 'w') do |f|
|
11
|
+
f.print(random_string(20))
|
12
|
+
end
|
13
|
+
filename
|
14
|
+
end
|
15
|
+
end
|
12
16
|
|
13
17
|
World(MixinSupport)
|
data/lib/rdoba/_version_.rb
CHANGED
data/lib/rdoba/a.rb
CHANGED
@@ -1,42 +1,42 @@
|
|
1
1
|
#!/usr/bin/ruby -KU
|
2
|
-
#
|
2
|
+
# frozen_string_literal: true
|
3
3
|
|
4
4
|
require 'rdoba/debug'
|
5
5
|
|
6
6
|
class Array
|
7
|
-
|
8
|
-
|
7
|
+
# TODO: => [] + class Index
|
8
|
+
def geta(index, options = {})
|
9
|
+
dbp11 "[geta] <<< array = #{inspect}, index = #{index.inspect}, options = #{options.inspect}"
|
9
10
|
options[:сокр] ||= @сокр
|
10
11
|
|
11
|
-
if index.
|
12
|
-
return self if
|
12
|
+
if index.instance_of?(Array)
|
13
|
+
return self if [[], ['']].include?(index)
|
14
|
+
|
13
15
|
index = index.clone
|
14
16
|
value = self[index.shift]
|
15
|
-
(value.
|
17
|
+
(value.instance_of?(Hash) or value.instance_of?(Array)) ? value.geta(index, options) : value
|
16
18
|
else
|
17
19
|
geta_value(index, options)
|
18
20
|
end
|
19
21
|
end
|
20
|
-
|
21
22
|
end
|
22
23
|
|
23
|
-
|
24
24
|
class Hash
|
25
|
-
|
26
|
-
protected
|
25
|
+
protected
|
27
26
|
|
28
27
|
def geta_value(cid, options = {})
|
29
|
-
res =
|
28
|
+
res =
|
29
|
+
(!cid || cid.empty?) && self || self[cid] ||
|
30
30
|
(options[:сокр] && (self[options[:сокр][cid]] || self[options[:сокр].reverse[cid]]))
|
31
31
|
|
32
|
-
if
|
33
|
-
|
32
|
+
if !res and options[:try_regexp]
|
33
|
+
keys.each do |key|
|
34
34
|
break res = self[key] if key.rmatch(cid)
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
35
|
+
|
36
|
+
next unless options[:сокр]
|
37
|
+
|
38
|
+
options[:сокр].each_pair do |val1, val2|
|
39
|
+
break res = self[key] if key.rmatch(cid.gsub(/#{val1}/, val2)) or key.rmatch(cid.gsub(/#{val2}/, val1))
|
40
40
|
end
|
41
41
|
end
|
42
42
|
end
|
@@ -44,47 +44,51 @@ protected
|
|
44
44
|
res
|
45
45
|
end
|
46
46
|
|
47
|
-
public
|
47
|
+
public
|
48
48
|
|
49
|
-
|
50
|
-
|
49
|
+
# TODO: => [] + class Index
|
50
|
+
def geta(index, options = {})
|
51
|
+
dbp11 "[geta] <<< hash = #{inspect}, index = #{index.inspect}, options = #{options.inspect}"
|
51
52
|
options[:сокр] ||= @сокр
|
52
53
|
|
53
|
-
if index.
|
54
|
-
return self if
|
54
|
+
if index.instance_of?(Array)
|
55
|
+
return self if [[], ['']].include?(index)
|
56
|
+
|
55
57
|
index = index.clone
|
56
58
|
value = geta_value(index.shift, options)
|
57
|
-
(value.
|
59
|
+
(value.instance_of?(Hash) or value.instance_of?(Array)) ? value.geta(index, options) : value
|
58
60
|
else
|
59
61
|
geta_value(index, options)
|
60
62
|
end
|
61
63
|
end
|
62
64
|
|
63
|
-
|
65
|
+
# TODO: => [] + class Index
|
66
|
+
def seta(index, value, options = {})
|
64
67
|
dbp11 "[seta] <<< index: #{index.inspect}, value: #{value.inspect}, options: #{options.inspect}"
|
65
68
|
options[:сокр] ||= @сокр
|
66
69
|
|
67
|
-
return self[index] = value if index.class != Array # TODO spec index
|
70
|
+
return self[index] = value if index.class != Array # TODO: spec index
|
68
71
|
|
69
72
|
back = 0
|
70
|
-
index =
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
back
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
73
|
+
index =
|
74
|
+
index.reverse.map do |x|
|
75
|
+
if x.empty?
|
76
|
+
back += 1
|
77
|
+
nil
|
78
|
+
elsif back > 0
|
79
|
+
back -= 1
|
80
|
+
nil
|
81
|
+
else
|
82
|
+
x
|
83
|
+
end
|
84
|
+
end.compact.reverse
|
81
85
|
dbp12 "[seta]> result index: #{index.inspect}"
|
82
86
|
|
83
87
|
obj = nil
|
84
88
|
o = self
|
85
89
|
dbp14 "[seta]>> self: #{o.inspect}"
|
86
90
|
set_idx = index.pop
|
87
|
-
par_class =
|
91
|
+
par_class = /^\d+$/.match?(set_idx) ? Array : Hash
|
88
92
|
par_idx = nil
|
89
93
|
index.each do |idx|
|
90
94
|
unless o
|
@@ -93,7 +97,7 @@ public
|
|
93
97
|
obj[par_idx] = o
|
94
98
|
end
|
95
99
|
obj = o
|
96
|
-
o =
|
100
|
+
o = obj.instance_of?(Hash) ? obj.geta_value(idx, options) : obj[idx]
|
97
101
|
dbp14 "[seta]>> cur idx: #{idx.inspect}, parent obj: #{obj.inspect}, obj: #{o.inspect}"
|
98
102
|
unless o
|
99
103
|
if idx == index.last
|
@@ -105,10 +109,8 @@ public
|
|
105
109
|
end
|
106
110
|
end
|
107
111
|
|
108
|
-
raise
|
112
|
+
raise 'Invalid path' unless o # TODO: special exception
|
109
113
|
|
110
114
|
o[set_idx] = value
|
111
115
|
end
|
112
|
-
|
113
116
|
end
|
114
|
-
|
data/lib/rdoba/bcd.rb
CHANGED
@@ -1,61 +1,78 @@
|
|
1
|
-
#
|
2
|
-
#
|
1
|
+
# frozen_string_literal: true
|
3
2
|
|
4
3
|
module BCD
|
5
|
-
class ParseError <
|
6
|
-
def initialize
|
4
|
+
class ParseError < RuntimeError
|
5
|
+
def initialize(msg = 'Invalid positive integer value'); end
|
6
|
+
end
|
7
7
|
|
8
|
-
class ConvertError <
|
9
|
-
def initialize
|
8
|
+
class ConvertError < RuntimeError
|
9
|
+
def initialize(msg = 'Invalid number has given'); end
|
10
|
+
end
|
10
11
|
|
11
12
|
def to_i
|
12
13
|
res = 0
|
13
14
|
mul = 1
|
14
|
-
|
15
|
-
def pow
|
15
|
+
each_byte do |c|
|
16
|
+
def pow(value, mul)
|
16
17
|
if value >= 10
|
17
|
-
raise ConvertError
|
18
|
+
raise ConvertError
|
19
|
+
end
|
20
|
+
|
18
21
|
value * mul
|
19
22
|
end
|
20
|
-
res += pow(
|
23
|
+
res += pow(c.ord & 0xF, mul)
|
21
24
|
mul *= 10
|
22
|
-
res += pow(
|
25
|
+
res += pow(c.ord >> 4, mul)
|
23
26
|
mul *= 10
|
24
27
|
end
|
25
|
-
res
|
28
|
+
res
|
29
|
+
end
|
26
30
|
|
27
|
-
def self.parse
|
31
|
+
def self.parse(value)
|
28
32
|
if value < 0
|
29
|
-
raise ParseError
|
33
|
+
raise ParseError
|
34
|
+
end
|
35
|
+
|
30
36
|
res = BCDString.new
|
31
37
|
if res.respond_to? :force_encoding
|
32
|
-
res.force_encoding(
|
38
|
+
res.force_encoding('ASCII-8BIT')
|
39
|
+
end
|
33
40
|
if value > 0
|
34
41
|
part = nil
|
35
42
|
while value > 0
|
36
|
-
|
43
|
+
value, mod = value.divmod 10
|
37
44
|
if part
|
38
|
-
res << (
|
45
|
+
res << ((mod << 4) | part).chr
|
39
46
|
part = nil
|
40
47
|
else
|
41
|
-
part = mod
|
48
|
+
part = mod
|
49
|
+
end
|
50
|
+
end
|
42
51
|
if part
|
43
|
-
res << part.chr
|
52
|
+
res << part.chr
|
53
|
+
end
|
44
54
|
else
|
45
|
-
res << 0.chr
|
46
|
-
|
55
|
+
res << 0.chr
|
56
|
+
end
|
57
|
+
res
|
58
|
+
end
|
59
|
+
end
|
47
60
|
|
48
61
|
class BCDString < String
|
49
62
|
include BCD
|
50
63
|
|
51
|
-
def initialize
|
64
|
+
def initialize(value = nil)
|
52
65
|
if value.is_a? Numeric
|
53
|
-
|
66
|
+
replace BCD.parse(value)
|
54
67
|
else
|
55
|
-
super value.to_s
|
68
|
+
super value.to_s
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
56
72
|
|
57
73
|
class Numeric
|
58
74
|
def to_bcd
|
59
75
|
# NOTE: return as plain LSB string
|
60
|
-
BCD.parse value
|
61
|
-
|
76
|
+
BCD.parse value
|
77
|
+
end
|
78
|
+
end
|
data/lib/rdoba/blank.rb
ADDED
data/lib/rdoba/combinations.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
#!/usr/bin/ruby
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
4
|
class Array
|
4
|
-
|
5
|
-
private
|
5
|
+
private
|
6
6
|
|
7
7
|
def __comby(i, size)
|
8
|
-
s = "0#{
|
9
|
-
v = { :
|
8
|
+
s = "0#{format('%.*b', size, i)}0"
|
9
|
+
v = { res: [], c0: 0, c1: 0, j: 0 }
|
10
10
|
|
11
11
|
def up1(v)
|
12
12
|
sub_j = v[:j] + v[:c1] + 1
|
@@ -17,7 +17,9 @@ private
|
|
17
17
|
|
18
18
|
def up0(v)
|
19
19
|
sub_j = v[:j] + v[:c0] - 1
|
20
|
-
self[v[:j]...sub_j].each do |x|
|
20
|
+
self[v[:j]...sub_j].each do |x|
|
21
|
+
v[:res] << [x]
|
22
|
+
end
|
21
23
|
v[:j] = sub_j
|
22
24
|
end
|
23
25
|
|
@@ -35,25 +37,25 @@ private
|
|
35
37
|
v[:res]
|
36
38
|
end
|
37
39
|
|
38
|
-
public
|
40
|
+
public
|
39
41
|
|
40
42
|
def each_comby(*args)
|
41
|
-
return self if
|
43
|
+
return self if empty? or !block_given?
|
44
|
+
|
42
45
|
if args.include?(:backward)
|
43
|
-
yield [
|
44
|
-
((1 << (
|
45
|
-
c = __comby(i,
|
46
|
+
yield [dup]
|
47
|
+
((1 << (size - 1)) - 2).downto(0) do |i|
|
48
|
+
c = __comby(i, size - 1)
|
46
49
|
yield c
|
47
50
|
end
|
48
51
|
else
|
49
|
-
0.upto((1 << (
|
50
|
-
c = __comby(i,
|
52
|
+
0.upto((1 << (size - 1)) - 2) do |i|
|
53
|
+
c = __comby(i, size - 1)
|
51
54
|
yield c
|
52
55
|
end
|
53
|
-
yield [
|
56
|
+
yield [dup]
|
54
57
|
end
|
55
58
|
|
56
|
-
|
59
|
+
self
|
57
60
|
end
|
58
61
|
end
|
59
|
-
|