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
@@ -0,0 +1,305 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
Допустим(/ꙇє примѣнена подпримѣсь \.([^\s]+) бисера рдоба/i) do |подпримѣсь|
|
4
|
+
require 'rdoba'
|
5
|
+
case подпримѣсь
|
6
|
+
when 'пуздро'
|
7
|
+
rdoba mixin: [:case]
|
8
|
+
when 'обратка'
|
9
|
+
rdoba mixin: [:reverse]
|
10
|
+
when 'ли_пущь'
|
11
|
+
rdoba mixin: [:empty]
|
12
|
+
when 'во_сл'
|
13
|
+
rdoba mixin: [:to_h]
|
14
|
+
when 'сравнена'
|
15
|
+
rdoba mixin: [:compare]
|
16
|
+
when 'режь_по'
|
17
|
+
rdoba mixin: [:split_by]
|
18
|
+
when 'жди_ьже'
|
19
|
+
rdoba mixin: [:wait_if]
|
20
|
+
when 'время'
|
21
|
+
rdoba mixin: [:time]
|
22
|
+
when 'пробь'
|
23
|
+
rdoba mixin: [:try]
|
24
|
+
else
|
25
|
+
raise
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
Допустим(/^у нас есть набор чисел$/) do
|
30
|
+
@набор = [1, 2, 3, 4, 5, 6, 7, 8]
|
31
|
+
end
|
32
|
+
|
33
|
+
Если(
|
34
|
+
/къ (кирилическу|латыньску) слову въ (верхнемъ|нижнемъ|смѣшанѣмъ) пуздрѣ ꙇє примѣненъ приꙇомъ :(ниспуздри|воспуздри)/
|
35
|
+
) do |ꙇезикъ, пуздро, приꙇомъ|
|
36
|
+
стр =
|
37
|
+
if /кирилическу/.match?(ꙇезикъ)
|
38
|
+
if /верхнемъ/.match?(пуздро)
|
39
|
+
'КИРИЛИЧЕСКЫ БУКЫ ЗРИЙ СІИ: Ѡ И Ꙍ'
|
40
|
+
elsif /нижнемъ/.match?(пуздро)
|
41
|
+
'кирилическы букы зрий сіи: ѡ и ꙍ'
|
42
|
+
else
|
43
|
+
'КиРиЛиЧеСкЫ бУкЫ зРиЙ сІи: Ѡ и Ꙍ'
|
44
|
+
end
|
45
|
+
elsif /верхнемъ/.match?(пуздро)
|
46
|
+
'LATIN LETTERS SEE THE FOLLOWING: ÆǞ'
|
47
|
+
elsif /нижнемъ/.match?(пуздро)
|
48
|
+
'latin letters see the following: æǟ'
|
49
|
+
else
|
50
|
+
'LaTiN lEtTeRs SeE tHe FoLlOwInG: æǞ'
|
51
|
+
end
|
52
|
+
|
53
|
+
@плодъ = (приꙇомъ =~ /ниспуздри/) && стр.downcase || стр.upcase
|
54
|
+
end
|
55
|
+
|
56
|
+
Если(/^рассечём его на чётные и нечётные$/) do
|
57
|
+
@чётъ, @нечётъ = @набор.split_by { |x| x.even? }
|
58
|
+
end
|
59
|
+
|
60
|
+
Если(/^спробуем вызвать метод :qwer пущя$/) do
|
61
|
+
@плодъ = nil.try(:qwer)
|
62
|
+
end
|
63
|
+
|
64
|
+
То(/^(кирилическо|латыньско) слово имаꙇє буквы въ (нижнемъ|верхнемъ) пуздрѣ$/) do |ꙇезикъ, пуздро|
|
65
|
+
плодъ =
|
66
|
+
if /кирилическо/.match?(ꙇезикъ)
|
67
|
+
(пуздро =~ /верхнемъ/) && 'КИРИЛИЧЕСКЫ БУКЫ ЗРИЙ СІИ: Ѡ И Ꙍ' || 'кирилическы букы зрий сіи: ѡ и ꙍ'
|
68
|
+
else
|
69
|
+
(пуздро =~ /верхнемъ/) && 'LATIN LETTERS SEE THE FOLLOWING: ÆǞ' || 'latin letters see the following: æǟ'
|
70
|
+
end
|
71
|
+
|
72
|
+
if @плодъ != плодъ
|
73
|
+
raise "Плодна Страза со значенꙇемъ '#{@плодъ}' должна имѣти значенꙇе " \
|
74
|
+
"'#{плодъ}'"
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
То(/^Стразовъ приꙇомъ :обратка( сѫ кракомъ| сѫ доведомъ)? повратє обратну Стразу$/) do |доведъ|
|
79
|
+
требе =
|
80
|
+
case доведъ
|
81
|
+
when nil
|
82
|
+
'акортс'
|
83
|
+
when /кракомъ/u
|
84
|
+
"\xB0\xD0\xBA\xD0\xBE\xD0\x80\xD1\x82\xD1\x81\xD1"
|
85
|
+
when /доведомъ/u
|
86
|
+
'карост'
|
87
|
+
end
|
88
|
+
|
89
|
+
исходъ =
|
90
|
+
case доведъ
|
91
|
+
when nil
|
92
|
+
'строка'.reverse
|
93
|
+
when /кракомъ/u
|
94
|
+
'строка'.reverse :byte_by_byte
|
95
|
+
when /доведомъ/u
|
96
|
+
'строка'.reverse 2
|
97
|
+
end
|
98
|
+
|
99
|
+
if исходъ != требе
|
100
|
+
raise "Ложнъ исходъ '#{исходъ}' ꙇє повратнъ отъ приꙇома :обратка#{доведъ}, требуꙇє '#{требе}'"
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
То(/^приꙇомъ :ли_пущь рода (пущь|лжа|нове вещи) повратє (вѣрнъ|лжъ)$/) do |вещь, поврать|
|
105
|
+
поврать = (поврать == 'вѣрнъ') && true || false
|
106
|
+
исходъ =
|
107
|
+
case вещь
|
108
|
+
when 'пущь'
|
109
|
+
nil.empty? == поврать
|
110
|
+
when 'лжа'
|
111
|
+
false.empty? == поврать
|
112
|
+
when 'нове вещи'
|
113
|
+
Object.new.empty? == поврать
|
114
|
+
end
|
115
|
+
unless исходъ
|
116
|
+
raise "Ложнъ исходъ ꙇє повратнъ отъ приꙇома :ли_пущь рода #{вещь}"
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
Если(
|
121
|
+
/^(ровнъ|двуглубнъ|триглубнъ) наборъ( сѫ одинакыми частьми)? ꙇє пречиненъ во словникъ( приꙇомомъ :во_сл сѫ клѵчемъ :кромѣ_двоꙇниковъ)?$/
|
122
|
+
) do |видъ, одинакъ, клѵчь|
|
123
|
+
@вещь =
|
124
|
+
case видъ
|
125
|
+
when 'ровнъ'
|
126
|
+
['aa', 0, 'bb', 1].to_h
|
127
|
+
when 'двуглубнъ'
|
128
|
+
if одинакъ
|
129
|
+
if клѵчь
|
130
|
+
[['aa', 0], ['aa', 0]].to_h(save_unique: true)
|
131
|
+
else
|
132
|
+
[['aa', 0], ['aa', 0]].to_h
|
133
|
+
end
|
134
|
+
else
|
135
|
+
[['aa', 0], ['bb', 1]].to_h
|
136
|
+
end
|
137
|
+
when 'триглубнъ'
|
138
|
+
[['aa', 0, 1], ['bb', [1, 0]]].to_h
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
То(/^тъꙇи имѣꙇє ровнъ словникъ сѫ (пущими |ровнѣми |двуглубнѣми )?значѣми$/) do |видъ|
|
143
|
+
@схъ =
|
144
|
+
if /пущими/u.match?(видъ)
|
145
|
+
{ 'aa' => nil, 0 => nil, 'bb' => nil, 1 => nil }
|
146
|
+
elsif /ровнѣми/u.match?(видъ)
|
147
|
+
{ 'aa' => 0, 'bb' => 1 }
|
148
|
+
else
|
149
|
+
{ 'aa' => [0, 1], 'bb' => [1, 0] }
|
150
|
+
end
|
151
|
+
|
152
|
+
if @вещь != @схъ
|
153
|
+
raise "Наборъ '#{@вещь}' требуꙇє быти '#{@схъ}'"
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
То(/^тъꙇи имѣꙇє ровнъ словникъ сѫ (однимъ|двами) двуглубн(?:ѣмъ|ѣмы) знач(?:ѣмъ|ѣмы)$/) do |видъ|
|
158
|
+
@схъ =
|
159
|
+
if /двами/.match?(видъ)
|
160
|
+
{ 'aa' => [0, 0] }
|
161
|
+
else
|
162
|
+
{ 'aa' => [0] }
|
163
|
+
end
|
164
|
+
|
165
|
+
if @вещь != @схъ
|
166
|
+
raise "Наборъ '#{@вещь}' требуꙇє быти '#{@схъ}'"
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
Если(/^имѣмы двѣ Стразы$/) do
|
171
|
+
@стры = %w[а҆́гнецъ а҆гкѵ́ра]
|
172
|
+
end
|
173
|
+
|
174
|
+
То(
|
175
|
+
/^приꙇомъ :сравнена двухъ Стразъ( сѫ презоромъ надъстрочниковъ( ꙇакъ словникъ)?)? повратє (безъ )?одна$/
|
176
|
+
) do |доведъ, подобье, знакъ|
|
177
|
+
поврать = (знакъ =~ /безъ/u) && -1 || 1
|
178
|
+
|
179
|
+
исходъ =
|
180
|
+
if доведъ
|
181
|
+
if подобье
|
182
|
+
@стры[0].compare_to(@стры[1], ignore_diacritics: true) == поврать
|
183
|
+
else
|
184
|
+
@стры[0].compare_to(@стры[1], :ignore_diacritics) == поврать
|
185
|
+
end
|
186
|
+
else
|
187
|
+
@стры[0].compare_to(@стры[1]) == поврать
|
188
|
+
end
|
189
|
+
|
190
|
+
unless исходъ
|
191
|
+
raise "Приꙇомъ :сравнена двухъ Стразъ#{доведъ}#{подобье} требуꙇє повратъти '#{поврать}'"
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
То(/^получим два набора чётных и нечётных чисел$/) do
|
196
|
+
expect(@чётъ).to be_eql([2, 4, 6, 8])
|
197
|
+
expect(@нечётъ).to be_eql([1, 3, 5, 7])
|
198
|
+
end
|
199
|
+
|
200
|
+
То(/^той вернёт пущь$/) do
|
201
|
+
expect(@плодъ).to be_nil
|
202
|
+
end
|
203
|
+
|
204
|
+
Если(/^спробуем подождать мало, чтобы условие не выполнилось$/) do
|
205
|
+
@плодъ = wait_if(1) { false }
|
206
|
+
end
|
207
|
+
|
208
|
+
Если(/^спробуем подождать мало, чтобы условие выполнилось$/) do
|
209
|
+
@плодъ = wait_if(1) { true }
|
210
|
+
end
|
211
|
+
|
212
|
+
Если(/^спробуем подождать долго, чтобы условие выполнилось$/) do
|
213
|
+
@плодъ =
|
214
|
+
begin
|
215
|
+
Timeout.timeout(2) do
|
216
|
+
wait_if(10) { true }
|
217
|
+
end
|
218
|
+
rescue Timeout::Error
|
219
|
+
nil
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
223
|
+
То(/^недождёмся$/) do
|
224
|
+
expect(@плодъ).to be_nil
|
225
|
+
end
|
226
|
+
|
227
|
+
То(/^той вернёт ложно$/) do
|
228
|
+
expect(@плодъ).to be_falsey
|
229
|
+
end
|
230
|
+
|
231
|
+
То(/^той вернёт исте$/) do
|
232
|
+
expect(@плодъ).to be_truthy
|
233
|
+
end
|
234
|
+
|
235
|
+
Если(/^спробуем вызвать метод :mtime кута временного$/) do
|
236
|
+
@кут = tmpfile
|
237
|
+
@время = File.mtime(@кут)
|
238
|
+
end
|
239
|
+
|
240
|
+
Если(/^спробуем вызвать метод :atime кута временного$/) do
|
241
|
+
@кут = tmpfile
|
242
|
+
@время = File.atime(@кут)
|
243
|
+
end
|
244
|
+
|
245
|
+
Если(/^спробуем вызвать метод :ctime кута временного$/) do
|
246
|
+
@кут = tmpfile
|
247
|
+
@время = File.ctime(@кут)
|
248
|
+
end
|
249
|
+
|
250
|
+
То(/^той вернёт верно время/) do
|
251
|
+
время = @время.strftime('%Y-%m-%d %H:%M:%S.%N %z')
|
252
|
+
expect(время).to be_eql(`stat -c %y #{@кут}`.strip)
|
253
|
+
end
|
254
|
+
|
255
|
+
Если(/^ꙇє примѣнена подпримѣсь невѣрна бисера рдоба$/) do
|
256
|
+
@проц = proc { rdoba mixin: [:false] }
|
257
|
+
end
|
258
|
+
|
259
|
+
То(/^исключение невѣрнѣ опции вызвано будетъ$/) do
|
260
|
+
expect { @проц.call }.to raise_error(Rdoba::Mixin::InvalidOption)
|
261
|
+
end
|
262
|
+
|
263
|
+
# #!/usr/bin/ruby -KU
|
264
|
+
#
|
265
|
+
# if $0 == __FILE__
|
266
|
+
# p s.to_res
|
267
|
+
# [1,2,3,4,5].each_comby do |c|
|
268
|
+
# p c
|
269
|
+
# end
|
270
|
+
#
|
271
|
+
# len = 4
|
272
|
+
# value = 100
|
273
|
+
# p sprintf("%.*X", len, value )
|
274
|
+
#
|
275
|
+
# s = ' 1221 eeee 4564 wwww ' + 258.to_p
|
276
|
+
# ppp = s.scanf(' %d %s %d %s %.2+c')
|
277
|
+
# p ppp
|
278
|
+
# p 258.to_p.to_i(String::BE)
|
279
|
+
#
|
280
|
+
# null = nil
|
281
|
+
# p null.class, null
|
282
|
+
# null <<= 'qweqweqweqwe'
|
283
|
+
# p null.class, null
|
284
|
+
# null << 'qweqweqweqwe'
|
285
|
+
# p null.class, null
|
286
|
+
# i = 12
|
287
|
+
# p sprintf("0x%X", i)
|
288
|
+
# p sprintf("%.3X", i)
|
289
|
+
#
|
290
|
+
# p '----------'
|
291
|
+
#
|
292
|
+
# str = <<STR
|
293
|
+
# <font size="4" face="Irmologion Ucs">и3зhде
|
294
|
+
# повелёніе t кeсарz ѓvгуста, написaти всю2
|
295
|
+
# вселeнную</font>
|
296
|
+
# STR
|
297
|
+
#
|
298
|
+
|
299
|
+
#
|
300
|
+
# str = '/font><font size="4">III</font><i> </i>греч.<font size="4"><i></i> </font><font size="4" face="Irmologion Ucs">Мёсzца ѓvгуста въ Gi-й дeнь. Слyжба с™и1телю и3 чудотв0рцу тЂхwну, є3пcкпу вор0нежскому.</font>13 августа, Тихона Воронежского, заголовок службы m_aug\13p.hip'
|
301
|
+
# re = /<font size="4" face="Irmologion Ucs">([ -"'-\?A-BD-HJ-\[\]`-hj-\}¤¦-§©«-®±µ-·»Ё-ЌЎ-яё-ќў-џҐ-ґ–-—‘-‚“-„†-•…‰‹-›€№™∙]+?)<\/font>/
|
302
|
+
#
|
303
|
+
# p(str.match re)
|
304
|
+
# end
|
305
|
+
#
|
data/features/support/env.rb
CHANGED
@@ -1,161 +1,51 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'rdoba'
|
2
|
-
require '
|
4
|
+
require 'tmpdir'
|
3
5
|
require 'open3'
|
4
6
|
require 'coveralls'
|
5
|
-
|
7
|
+
require 'simplecov'
|
8
|
+
require 'rspec/expectations'
|
6
9
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
RdobaSimInHead=<<HEAD
|
14
|
-
#!/usr/bin/env ruby
|
10
|
+
# specific external test/development libraries
|
11
|
+
#
|
12
|
+
#
|
13
|
+
Coveralls.wear!
|
14
|
+
SimpleCov.start
|
15
|
+
##############################################
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
end
|
21
|
-
end
|
17
|
+
RdobaSimSimpleHead = <<~HEAD
|
18
|
+
#!/usr/bin/env ruby
|
19
|
+
|
20
|
+
require 'rdoba'
|
22
21
|
HEAD
|
23
22
|
|
24
|
-
RdobaSimClsHead
|
25
|
-
#!/usr/bin/env ruby
|
26
|
-
|
27
|
-
require 'rdoba'
|
28
|
-
class Cls
|
23
|
+
RdobaSimClsHead = <<~HEAD
|
24
|
+
#!/usr/bin/env ruby
|
25
|
+
|
26
|
+
require 'rdoba'
|
27
|
+
class Cls
|
29
28
|
HEAD
|
30
29
|
|
31
|
-
def format
|
30
|
+
def format(str)
|
32
31
|
puts str
|
33
|
-
|
32
|
+
' ' * @deep + str + "\n"
|
33
|
+
end
|
34
34
|
|
35
35
|
def store
|
36
|
-
file = @inithead + @init + @echo + (
|
36
|
+
file = @inithead + @init + @echo + ("end\n" * @deep)
|
37
37
|
puts file
|
38
|
-
File.open(
|
39
|
-
f.puts file
|
40
|
-
|
41
|
-
def match_keywords keystr
|
42
|
-
keys = ( keystr || '' ).split( /[,:\s]/ ).map do |k|
|
43
|
-
[ :basic, :extended, :enter, :leave, :compat, :timestamp, :pid,
|
44
|
-
:function_name, :function_line ].include?( k.to_sym ) && k.to_sym || nil
|
45
|
-
end.compact ; end
|
46
|
-
|
47
|
-
def rdoba_sim sub, cmd, *args
|
48
|
-
echo = nil
|
49
|
-
case sub
|
50
|
-
when :log, :debug
|
51
|
-
case cmd
|
52
|
-
when :init
|
53
|
-
opts = match_keywords args[ 1 ]
|
54
|
-
opts = opts.size > 1 && opts || opts.size > 0 && opts[ 0 ] || nil
|
55
|
-
|
56
|
-
if args[ 2 ] == 'class'
|
57
|
-
@deep = 1
|
58
|
-
@inithead = RdobaSimClsHead
|
59
|
-
else
|
60
|
-
@deep = 0
|
61
|
-
@inithead = RdobaSimSimpleHead ; end
|
62
|
-
|
63
|
-
param = case args[ 0 ]
|
64
|
-
when 'io'
|
65
|
-
{ :io => "File.new( 'tmp.log', 'w+' )", :functions => :basic }
|
66
|
-
when 'as'
|
67
|
-
{ :as => ":log", :functions => :basic }
|
68
|
-
when 'in'
|
69
|
-
@inithead = RdobaSimInHead
|
70
|
-
{ :in => "Cls", :functions => :basic }
|
71
|
-
when 'prefix'
|
72
|
-
# basic|extended|enter|leave|compat
|
73
|
-
{ args[ 0 ].to_sym => opts, :functions => :basic }
|
74
|
-
when 'functions'
|
75
|
-
{ args[ 0 ].to_sym => opts }
|
76
|
-
else
|
77
|
-
{ :functions => :basic }
|
78
|
-
end
|
79
|
-
|
80
|
-
param = "{" + ( param ).to_a.map do |v|
|
81
|
-
"#{v[ 0 ].inspect} => #{v[ 1 ].is_a?( String ) &&
|
82
|
-
v[ 1 ] || v[ 1 ].inspect}" end.join(',') + "}"
|
83
|
-
@init = " " * @deep + "rdoba :#{sub} => #{param}\n"
|
84
|
-
puts @init
|
85
|
-
@echo = ''
|
86
|
-
|
87
|
-
when :func
|
88
|
-
call = case args[ 0 ]
|
89
|
-
when 'keyword'
|
90
|
-
'log'
|
91
|
-
when 'invalid keyword'
|
92
|
-
'errlog'
|
93
|
-
when /^db/
|
94
|
-
@echo << "self.dbgl = 0xff\n"
|
95
|
-
args[ 0 ]
|
96
|
-
else
|
97
|
-
'self'
|
98
|
-
end
|
99
|
-
|
100
|
-
sep = ( args[ 1 ] == :e ) && '.' || ' '
|
101
|
-
param = []
|
102
|
-
args[ 2..-1 ].each do |arg|
|
103
|
-
case arg
|
104
|
-
when NilClass
|
105
|
-
when Symbol
|
106
|
-
param << " #{arg}"
|
107
|
-
else
|
108
|
-
param << " #{arg.inspect}" ; end ; end
|
109
|
-
str = "#{call}#{sep}#{args[ 1 ]}#{param.join(',')}"
|
110
|
-
echo = format str
|
111
|
-
@echo << echo
|
112
|
-
while @deep > 0
|
113
|
-
@deep -= 1
|
114
|
-
@echo << ( format "end" ) ; end
|
115
|
-
|
116
|
-
when :create
|
117
|
-
@echo << ( format "Cls.new" )
|
118
|
-
|
119
|
-
when :call
|
120
|
-
@echo << ( format "Cls.singleton" )
|
121
|
-
|
122
|
-
when :def
|
123
|
-
if @inithead == RdobaSimClsHead
|
124
|
-
@deep = 1
|
125
|
-
else
|
126
|
-
@deep = 0 ; end
|
127
|
-
echo = case args[ 0 ]
|
128
|
-
when :init
|
129
|
-
format 'def initialize'
|
130
|
-
when :single
|
131
|
-
format 'def self.singleton'
|
132
|
-
end
|
133
|
-
@deep += 1
|
134
|
-
@echo << echo
|
135
|
-
|
136
|
-
when :exec
|
137
|
-
if !@echo.empty?
|
138
|
-
store
|
139
|
-
puts '-' * 15
|
140
|
-
|
141
|
-
File.chmod 0755, 'tmp.rb'
|
142
|
-
Open3.popen3( "./tmp.rb" ) do |stdin, stdout, stderr, wait_thr|
|
143
|
-
@out = stdout.read
|
144
|
-
@err = stderr.read
|
145
|
-
end
|
146
|
-
@echo = ''
|
147
|
-
end
|
148
|
-
res = case args[ 0 ]
|
149
|
-
when :file
|
150
|
-
File.new( 'tmp.log', 'r' ).read
|
151
|
-
when :stdout
|
152
|
-
@out
|
153
|
-
when :stderr
|
154
|
-
@err;
|
155
|
-
else return; end
|
156
|
-
puts res
|
157
|
-
res
|
158
|
-
end
|
38
|
+
File.open(@tmpfile, 'w+') do |f|
|
39
|
+
f.puts file
|
159
40
|
end
|
160
41
|
end
|
161
42
|
|
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) }
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module MixinSupport
|
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
|
7
|
+
|
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
|
16
|
+
|
17
|
+
World(MixinSupport)
|
data/html/.keep
ADDED
File without changes
|
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
|
-
|