rdoba 0.9.1 → 0.9.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. checksums.yaml +7 -7
  2. data/.gitignore +4 -0
  3. data/.travis.yml +28 -0
  4. data/CHANGES.md +6 -0
  5. data/Gemfile +5 -0
  6. data/README.md +87 -108
  7. data/Rakefile +62 -54
  8. data/TODO +6 -0
  9. data/features/mixin.feature +85 -0
  10. data/features/step_definitions/mixin_steps.rb +305 -0
  11. data/features/support/env.rb +35 -145
  12. data/features/support/mixin_support.rb +17 -0
  13. data/html/.keep +0 -0
  14. data/lib/rdoba/_version_.rb +3 -1
  15. data/lib/rdoba/a.rb +44 -42
  16. data/lib/rdoba/bcd.rb +43 -26
  17. data/lib/rdoba/blank.rb +14 -0
  18. data/lib/rdoba/combinations.rb +17 -15
  19. data/lib/rdoba/common.rb +53 -68
  20. data/lib/rdoba/debug.rb +9 -3
  21. data/lib/rdoba/deploy.rb +55 -50
  22. data/lib/rdoba/dup.rb +31 -31
  23. data/lib/rdoba/fe.rb +6 -5
  24. data/lib/rdoba/gem.rb +33 -29
  25. data/lib/rdoba/hashorder.rb +24 -24
  26. data/lib/rdoba/io.rb +81 -74
  27. data/lib/rdoba/merge.rb +21 -0
  28. data/lib/rdoba/mixin/time.rb +17 -0
  29. data/lib/rdoba/mixin/try.rb +11 -0
  30. data/lib/rdoba/mixin/try_1_9_0.rb +9 -0
  31. data/lib/rdoba/mixin/wait_if.rb +27 -0
  32. data/lib/rdoba/mixin.rb +373 -52
  33. data/lib/rdoba/numeric.rb +19 -17
  34. data/lib/rdoba/os.rb +127 -0
  35. data/lib/rdoba/re.rb +4 -4
  36. data/lib/rdoba/require.rb +24 -19
  37. data/lib/rdoba/roman.rb +32 -22
  38. data/lib/rdoba/strings.rb +6 -144
  39. data/lib/rdoba/yaml.rb +20 -18
  40. data/lib/rdoba.rb +50 -47
  41. data/rdoba.gemspec +33 -26
  42. data/tddium.yml +11 -0
  43. metadata +184 -77
  44. data/features/bcd.feature +0 -29
  45. data/features/log.feature +0 -206
  46. data/features/step_definitions/bcd_steps.rb +0 -69
  47. data/features/step_definitions/log_steps.rb +0 -164
  48. data/lib/rdoba/log.rb +0 -248
  49. data/test/helper.rb +0 -18
  50. data/test/rdoba_test.rb.stub +0 -59
  51. data/test/test_rdoba.rb +0 -7
@@ -1,164 +0,0 @@
1
- When /appl(?:y|ied) Rdoba (Log|Debug) module(?: with set([\w\s,:]+ keywords?| a file name) for :(io|as|in|functions|prefix) option| with an (invalid) :io option value)?(?: inside a (class))?/ do |kind, subs, opt, invalid, cls|
2
- rdoba_sim kind.downcase.to_sym, :init, opt, subs, cls
3
- end
4
-
5
- When /issue a call to the function/ do
6
- rdoba_sim :log, :call
7
- end
8
-
9
- When /issue a creation of the class/ do
10
- rdoba_sim :log, :create
11
- end
12
-
13
- When /(issue|define) an output of an? (variable|number|string|array)(?: inside an? (initializer|singleton function))?(?: using (?:the|an?) (keyword|invalid keyword|class))?/ do |issue, subject, inside, cond|
14
-
15
- case inside
16
- when 'initializer'
17
- rdoba_sim :log, :def, :init
18
- when 'singleton function'
19
- rdoba_sim :log, :def, :single ; end
20
-
21
- func = :func
22
- case subject
23
- when 'variable'
24
- rdoba_sim :log, func, cond, :>, { variable: 'value' }
25
- when 'number'
26
- rdoba_sim :log, func, cond, :>, 1
27
- when 'string'
28
- rdoba_sim :log, func, cond, :>, "string"
29
- when 'array'
30
- rdoba_sim :log, func, cond, :>, [ 'array value1', 'array value2' ] ; end ; end
31
-
32
- When /issue an? :(extended|info|warn|enter|leave|compat) output of a variable/ do |key|
33
- case key
34
- when 'extended'
35
- rdoba_sim :log, :func, :self, :>>, { variable: 'value' }
36
- when 'info'
37
- rdoba_sim :log, :func, :self, :*, { variable: 'value' }
38
- when 'warn'
39
- rdoba_sim :log, :func, :self, :%, { variable: 'value' }
40
- when 'enter'
41
- rdoba_sim :log, :func, :self, :+, { variable: 'value' }
42
- when 'leave'
43
- rdoba_sim :log, :func, :self, :-, true # TODO check return
44
- when 'compat'
45
- rdoba_sim :log, :func, :dbp11, "'variable: \"value\"'" ; end ; end
46
-
47
- When /issue an output of the thrown (exception|standard error)(.*)/ do |type, note|
48
- case type
49
- when 'exception'
50
- if note =~ /out/
51
- rdoba_sim :log, :func, :self, :e, :'Exception.new', :$stdout
52
- else
53
- rdoba_sim :log, :func, :self, :e, :'Exception.new' ; end
54
- when 'standard error'
55
- if note =~ /notification/
56
- rdoba_sim :log, :func, :self, :e, :'StandardError.new',
57
- [ 'standard error extended info' ]
58
- else
59
- rdoba_sim :log, :func, :self, :e, :'StandardError.new' ; end ; end ; end
60
-
61
- When /look into(?: the)? (stdout|stderr|file|IO)/ do |ioname|
62
- @res = case ioname
63
- when 'file'
64
- rdoba_sim :log, :exec, :file
65
- when 'IO'
66
- rdoba_sim :log, :exec, :io
67
- when 'stdout'
68
- rdoba_sim :log, :exec, :stdout
69
- when 'stderr'
70
- rdoba_sim :log, :exec, :stderr; end ; end
71
-
72
- When /(remove|add) :(basic|extended|info|warn|enter|leave|compat) keyword.* :(functions) option/ do |act, key, opt|
73
- if act == 'remove'
74
- rdoba_sim :log, :func, :self, :>=, [ key.to_sym ]
75
- else
76
- rdoba_sim :log, :func, :self, :<=, [ key.to_sym ] ; end ; end
77
-
78
- When /clear the :(functions) option/ do |opt|
79
- rdoba_sim :log, :func, :self, :>=, [ :* ]
80
- end
81
-
82
- Then /see the (variable|string|number|array|'true' value) output(?: with the :(basic|extended|info|warn|enter|leave) notice)?(?: preficed with the :(.*))?/ do |subject, notice, prefices|
83
- case subject
84
- when 'variable'
85
- sym = notice && { 'basic' => '>', 'extended' => '>>', 'info' => '***',
86
- 'warn' => '%%%', 'enter' => '<<<', 'leave' => '>>>' }[ notice ] || '>'
87
- symr = sym.to_s.gsub ( '*' ) do |x| "\\#{x}" end
88
- prefices = match_keywords prefices
89
- if prefices.empty?
90
- if @res !~ /variable: "value"/
91
- raise "Invalid answer: #{@res}, must be \"variable: \"value\"" ; end
92
- else
93
- case prefices
94
- when [:timestamp]
95
- if @res !~ /\[\d\d:\d\d:\d\d\.\d{9}\]#{symr} variable: "value"/
96
- raise "Invalid answer: #{@res.chomp}, must be like " +
97
- "[00:00:00.000000000]#{sym} variable: \"value\"" ; end
98
- when [:timestamp, :pid]
99
- if @res !~ /\[\d\d:\d\d:\d\d\.\d{9}\]\{\d+\}#{symr} variable: "value"/
100
- raise "Invalid answer: #{@res.chomp}, must be like " +
101
- "[00:00:00.000000000]{0000}#{sym} variable: \"value\"" ; end
102
- when [:timestamp, :pid, :function_name]
103
- if @res !~ /\[\d\d:\d\d:\d\d\.\d{9}\]\{\d+\}\(.+\)#{symr} variable: "value"/
104
- raise "Invalid answer: #{@res.chomp}, must be like " +
105
- "[00:00:00.000000000]{0000}(name)#{sym} variable: \"value\"" ; end
106
- when [:timestamp, :pid, :function_name, :function_line]
107
- if @res !~ /\[\d\d:\d\d:\d\d\.\d{9}\]\{\d+\}\([^:]+:\d+\)#{symr} variable: "value"/
108
- raise "Invalid answer: #{@res.chomp}, must be like " +
109
- "[00:00:00.000000000]{0000}(name:0)#{sym} variable: \"value\"" ; end
110
- else
111
- raise "Invalid answer: #{@res}"
112
- end
113
- end
114
- when 'string'
115
- if @res !~ /string/
116
- raise "Invalid answer: #{@res}, must be \"string\"" ; end
117
- when 'number'
118
- if @res !~ /1/
119
- raise "Invalid answer: #{@res.inspect}, must be \"1\"" ; end
120
- when "'true' value"
121
- if @res !~ /true/
122
- raise "Invalid answer: #{@res.inspect}, must be \"true\"" ; end
123
- when 'array'
124
- if @res !~ /array value1, array value2/
125
- raise "Invalid answer: #{@res.inspect}, must be an enum: \"array value1, array value2\"" ; end ; end ; end
126
-
127
- Then /see the (standard error|exception) info(.*)/ do |subject, notice|
128
- case subject
129
- when 'exception'
130
- if @res !~/Exception:%> Exception/
131
- raise "Invalid answer: #{@res.inspect}, must be like " +
132
- "'Exception:%> Exception'" ; end
133
- when 'standard error'
134
- if notice =~ /notification/
135
- if @res !~ /StandardError:%> StandardError\n\tstandard error extended info/
136
- raise "Invalid answer: #{@res.inspect}, must be like " +
137
- "'StandardError:%> StandardError\n\tstandard error " +
138
- "extended info'" ; end
139
- else
140
- if @res !~ /StandardError:%> StandardError/
141
- raise "Invalid answer: #{@res.inspect}, must be like " +
142
- "'StandardError:%> StandardError'" ; end ; end ; end ; end
143
-
144
- Then /see(?: a| the)? (nothing|warning|.* error exception)/ do |subject|
145
- case subject
146
- when 'nothing'
147
- if !@res.empty?
148
- raise "Invalid answer: #{@res.inspect}, must be empty" ; end
149
- when 'warning'
150
- if @res !~ /Warning:/
151
- raise "Invalid answer: #{@res.inspect}, must be a warning " +
152
- "with the description" ; end
153
- 'log\': main is not a class/module (TypeError)'
154
- when /no method error/
155
- if @res !~ /undefined method .* \(NoMethodError\)/
156
- raise "Invalid answer: #{@res.inspect}, must notify" +
157
- " that the interpreter has not found the specified method" ; end
158
- when /name error/
159
- if @res !~ /undefined local variable or method .* \(NameError\)/
160
- raise "Invalid answer: #{@res.inspect}, must notify" +
161
- " that the the specified name isn't declared" ; end
162
- else
163
- raise "Invalid answer: #{@res.inspect}" ; end ; end
164
-
data/lib/rdoba/log.rb DELETED
@@ -1,248 +0,0 @@
1
- # encoding: utf-8
2
-
3
- module Rdoba
4
- def self.log options = {}
5
- # options: {
6
- # :as - name of method to apply the log functions, default: self
7
- # :in - name of class or namespace to implement to the log, default: Kernel
8
- # :functions = [
9
- # :basic
10
- # :warn
11
- # :info
12
- # :enter
13
- # :leave
14
- # :extended
15
- # :compat - enable old style log strings dbgXX
16
- # ]
17
- # :prefix = [
18
- # :timestamp
19
- # :pid
20
- # :function_name
21
- # :function_line
22
- # ]
23
- # :io - An IO object to send log output to, default is $stdout
24
- # }
25
- # if empty the default value (enter, leave) is applied
26
- # format of log message is the following:
27
- # [<timestamp>]{pid}(<function name>)<log type> <debug text>"
28
- # TODO add enum of options hash to convert values to symbols
29
- # TODO make common format, and format for each of methods >, >>, +, -, %, *
30
- # TODO add syntax redefinition ability for the methods >, >>, +, -, %, *
31
- # TODO add multiple output (to more than only the IO)
32
-
33
- # options[ :io ] = File.new('txt.log','w+')
34
- # STDERR.puts options.inspect
35
- # STDERR.puts options[ :io ].method( :puts ).inspect
36
- # options.map
37
- funcname = ( options[ :as ] || :self ).to_s.to_sym
38
- pfx = ';if true;(Rdoba::Log::log @@rdoba_log_io_method,"' #TODO remove if
39
- io = options[ :io ] || $stdout
40
- io_m = io.method :puts
41
- if prefix = ( options[ :prefix ].is_a?( Array ) && options[ :prefix ] ||
42
- [ options[ :prefix ] ] )
43
- if prefix.include?( :timestamp )
44
- pfx << '[#{Time.now.strftime( "%H:%M:%S.%N" )}]'; end
45
- if prefix.include?( :pid )
46
- pfx << '{#{Process.pid}}'; end
47
- if prefix.include?( :function_name )
48
- if prefix.include?( :function_line )
49
- pfx << '(#{m,f,l=get_stack_function_data_at_level(2);f+":"+l})'
50
- else
51
- pfx << '(#{get_stack_function_data_at_level(2)[1]})'; end ; end ; end
52
-
53
- target = options[ :in ] || Kernel
54
- # STDERR.puts "self: #{self.to_s}"
55
- # STDERR.puts "funcname: #{funcname.inspect}"
56
- # STDERR.puts "target: #{target.inspect}"
57
-
58
- initfunc = Proc.new do
59
- self.class_variable_set :@@rdoba_log_prefix, pfx
60
- self.class_variable_set :@@rdoba_log_io_method, io_m
61
- extend Rdoba::Log::ClassFunctions
62
- include Rdoba::Log::Functions
63
- self <= options[ :functions ] ; end
64
-
65
- if funcname == :self
66
- if target.to_s != 'main'
67
- # CASE: class Cls; def method; self > end; end
68
- target.instance_eval &initfunc ; end
69
- # CASE: main { self > }
70
- # CASE: class Cls; self > end
71
- target.class.instance_eval &initfunc
72
- else
73
- host = ( target.to_s == 'main' && Kernel || target ) ## TODO check and remove
74
- if target.to_s != 'main'
75
- # CASE: class Cls; log > end
76
- target.class.class_eval "class RdobaDebug;end"
77
- target.class.send :class_eval, "def #{funcname};@#{funcname}||=RdobaDebug.new;end"
78
- target.class::RdobaDebug.class_eval &initfunc ; end
79
- # CASE: main { log > }
80
- # CASE: class Cls; def method; log > end; end
81
- host.class_eval "class RdobaDebug;end"
82
- host.send :class_eval, "def #{funcname};@#{funcname}||=RdobaDebug.new;end"
83
- host::RdobaDebug.class_eval &initfunc ; end
84
-
85
- # STDERR.puts 2
86
- # STDERR.puts target.inspect
87
- # STDERR.puts target.class.methods.sort.inspect
88
- =begin
89
- target.class.instance_eval do # main { self > }
90
- # target.class_eval do # main { log > }
91
- self.class_variable_set( :@@log_prefix, pfx )
92
- self.class_variable_set( :@@log_io_method, io_m )
93
- extend Rdoba::Log::ClassFunctions
94
- include Rdoba::Log::Functions
95
- STDERR.puts pfx
96
- STDERR.puts io_m.inspect
97
- self <= functions; end;
98
- =end
99
- end; end
100
-
101
- module Rdoba
102
- module Log
103
- class Error < StandardError
104
- def initialize options = {}
105
- case options
106
- when :compat
107
- "Debug compatibility mode can't be enabled for " +
108
- "the specified object"
109
- when :main
110
- "An :as option can't be default or set to 'self' value for " +
111
- "a main application. Please set up it correctly"; end; end; end
112
-
113
- module Functions
114
- def <= functions = []
115
- self.class <= functions; end
116
-
117
- def >= functions = []
118
- self.class >= functions; end
119
-
120
- def e *args
121
- io = case args.last
122
- when IO
123
- args.pop
124
- else
125
- $stderr ; end
126
- e = $! || args.shift
127
- dump = ( [ $@ || args.shift ] + args ).flatten.compact
128
- io.send :puts, "#{e.class}:%> #{e}\n\t#{dump.join("\n\t")}"; end
129
-
130
- def get_stack_function_data_at_level( level )
131
- raise Exception
132
- rescue Exception
133
- #TODO check match a method containing '`'
134
- $@[ level ] =~ /([^\/]+):(\d+):in `(.*?)'$/
135
- [ $1, $3, $2 ]; end; end
136
-
137
- module ClassFunctions
138
- def <= functions
139
- functions = Rdoba::Log::update_functions functions, self, :+
140
- pfx = self.class_variable_get :@@rdoba_log_prefix
141
- code = Rdoba::Log::make_code functions, pfx, self
142
- self.class_eval code; end
143
-
144
- def >= functions # TODO make check for instance log, not only for class
145
- functions = Rdoba::Log::update_functions functions, self, :-
146
- pfx = self.class_variable_get :@@rdoba_log_prefix
147
- code = Rdoba::Log::make_code functions, pfx, self
148
- self.class_eval code; end; end
149
-
150
- def self.update_functions functions, obj, method
151
- if functions.is_a?( Array ) && functions.include?( :* )
152
- functions = [ :basic, :enter, :leave, :warn, :info, :extended, :compat ]
153
- end
154
- cf = begin
155
- obj.class_variable_get :@@rdoba_log_functions
156
- rescue NameError
157
- [] ; end
158
- functions = cf.send( method, functions.is_a?( Array ) && functions ||
159
- functions.is_a?( NilClass) && [] || [ functions.to_s.to_sym ] )
160
- obj.class_variable_set :@@rdoba_log_functions, functions
161
- functions
162
- end
163
-
164
- def self.make_code functions, pfx, obj
165
- code = ''
166
- psfx = ' ",params);end;end;'
167
- if functions.include?( :enter )
168
- code << 'def + *params' + pfx + '<<<' + psfx
169
- else
170
- code << 'def + *params;end;'; end
171
- if functions.include?( :leave )
172
- code << 'def - ev' + pfx + '>>> ",[[ev.inspect]]);end;ev;end;'
173
- else
174
- code << 'def - ev;ev;end;'; end
175
- if functions.include?( :basic )
176
- code << "def > *params#{pfx}>#{psfx}"
177
- else
178
- code << 'def > *params;end;'; end
179
- if functions.include?( :extended )
180
- code << 'def >> *params' + pfx + '>>' + psfx
181
- else
182
- code << 'def >> *params;end;'; end
183
- if functions.include?( :warn )
184
- code << "def % *params#{pfx}%%%#{psfx}"
185
- else
186
- code << 'def % *params;end;'; end
187
- if functions.include?( :info )
188
- code << "def * *params#{pfx}***#{psfx}"
189
- else
190
- code << 'def * *params;end;'; end
191
- if functions.include?( :compat )
192
- obj.send :include, Rdoba::Log::DebugCompat
193
- code << "$dbgl_#{self.class}=0;"
194
- (1..0xF).each do |x|
195
- (1..0xF).each do |y|
196
- idx = sprintf "%x%x", x, y
197
- code << "def dbp#{idx}(text); dbp(0x#{idx},text); end;"
198
- code << "def dbg#{idx}(text); dbg(0x#{idx},text); end;"; end; end; end
199
- code; end
200
-
201
- def self.log io_m, prefix, params
202
- text = prefix
203
- text << params.map do |prm|
204
- case prm
205
- when Hash
206
- r = []
207
- prm.each do |key, value| r << "#{key}: #{value.inspect}" end
208
- r.join(", ")
209
- when Array
210
- prm.join(', ')
211
- when String
212
- prm
213
- else
214
- prm.inspect
215
- end
216
- end.join(', ')
217
- # NOTE: the shell over text id requires to proper output
218
- # in multiprocess environment
219
- io_m.call "#{text}\n"; end
220
-
221
- module DebugCompat
222
- def dbgl
223
- @dbgl; end
224
-
225
- def dbgl= level
226
- @dbgl = level; end
227
-
228
- def dbc level
229
- level = level.to_i
230
- if level > 0
231
- clevel = @dbgl || begin
232
- eval "$dbgl_#{self.class}"
233
- rescue
234
- nil; end
235
- clevel || ( clevel.to_i & level ) == level
236
- else
237
- false; end; end
238
-
239
- def dbp level, text
240
- if dbc level
241
- Kernel.puts text; end; end
242
-
243
- def dbg level, code, vars = {}
244
- if dbc level
245
- if vars
246
- vars.each_pair do |var, value|
247
- instance_variable_set( var, value ); end; end
248
- eval code; end; end; end ;end; end
data/test/helper.rb DELETED
@@ -1,18 +0,0 @@
1
- require 'rubygems'
2
- require 'bundler'
3
- begin
4
- Bundler.setup(:default, :development)
5
- rescue Bundler::BundlerError => e
6
- $stderr.puts e.message
7
- $stderr.puts "Run `bundle install` to install missing gems"
8
- exit e.status_code
9
- end
10
- require 'test/unit'
11
- require 'shoulda'
12
-
13
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
- $LOAD_PATH.unshift(File.dirname(__FILE__))
15
- require 'rdoba'
16
-
17
- class Test::Unit::TestCase
18
- end
@@ -1,59 +0,0 @@
1
- #!/usr/bin/ruby -KU
2
-
3
- if $0 == __FILE__
4
- s = 'АцWуУуqцууууЦ+-* | »«1«2+121»'
5
- k = s.ord
6
- p s
7
- p s.downcase
8
- p s.downcase(String::FirstChar)
9
- p s.upcase
10
- p s.upcase(String::FirstChar)
11
- p s.to_res
12
- [1,2,3,4,5].each_comby do |c|
13
- p c
14
- end
15
-
16
- len = 4
17
- value = 100
18
- p sprintf("%.*X", len, value )
19
-
20
- s = ' 1221 eeee 4564 wwww ' + 258.to_p
21
- ppp = s.scanf(' %d %s %d %s %.2+c')
22
- p ppp
23
- p 258.to_p.to_i(String::BE)
24
- lll = 3
25
- lll.debug = 1
26
- lll.dbgF2("puts(1)")
27
- lll.debug = 0x2
28
- lll.dbgF2("puts(2)")
29
- lll.debug = 0xF3
30
- lll.dbgF2("puts(3)")
31
- lll.debug = 0xF2
32
- lll.dbpF2("4")
33
-
34
- null = nil
35
- p null.class, null
36
- null <<= 'qweqweqweqwe'
37
- p null.class, null
38
- null << 'qweqweqweqwe'
39
- p null.class, null
40
- i = 12
41
- p sprintf("0x%X", i)
42
- p sprintf("%.3X", i)
43
-
44
- p '----------'
45
-
46
- str = <<STR
47
- <font size="4" face="Irmologion Ucs">и3зhде
48
- повелёніе t кeсарz ѓvгуста, написaти всю2
49
- вселeнную</font>
50
- STR
51
-
52
-
53
- 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'
54
- re = /<font size="4" face="Irmologion Ucs">([ -"'-\?A-BD-HJ-\[\]`-hj-\}¤¦-§©«-®±µ-·»Ё-ЌЎ-яё-ќў-џҐ-ґ–-—‘-‚“-„†-•…‰‹-›€№™∙]+?)<\/font>/
55
-
56
- p(str.match re)
57
- end
58
-
59
-
data/test/test_rdoba.rb DELETED
@@ -1,7 +0,0 @@
1
- require 'helper'
2
-
3
- class TestRdoba < Test::Unit::TestCase
4
- should "probably rename this file and start testing for real" do
5
- flunk "hey buddy, you should probably rename this file and start testing for real"
6
- end
7
- end