rdoba 0.9.3 → 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.
data/lib/rdoba/common.rb CHANGED
@@ -1,13 +1,14 @@
1
1
  #!/usr/bin/ruby -KU
2
- #coding:utf-8
2
+ # frozen_string_literal: true
3
3
 
4
4
  class Object
5
5
  def xor(val1)
6
- val0 = (not not self)
7
- ((val0) and (not val1)) or ((not val0) and (val1))
6
+ val0 = !!self
7
+ (val0 and !val1) or (!val0 and val1)
8
8
  end
9
9
 
10
- def co(method, *args) #calls any method
10
+ # calls any method
11
+ def co(method, *_args)
11
12
  eval "#{method}(*args)"
12
13
  end
13
14
 
@@ -20,34 +21,36 @@ class Object
20
21
  opts.each do |opt|
21
22
  case opt.class.to_s.to_sym
22
23
  when :Hash
23
- opt.each do |x,y| v[x] = y end
24
+ opt.each do |x, y|
25
+ v[x] = y
26
+ end
24
27
  when :Array
25
- opt.each do |x| v[x] = true end
28
+ opt.each do |x|
29
+ v[x] = true
30
+ end
26
31
  when :Symbol
27
- v[opt] = true
32
+ v[opt] = true
28
33
  end
29
34
  end
30
35
  v
31
36
  end
32
37
 
33
38
  def apply_opts(opts)
34
- parse_opts(opts).each do |x,y|
35
- self.instance_variable_set("@#{x}".to_sym, y)
36
- end
39
+ parse_opts(opts).each do |x, y| instance_variable_set("@#{x}".to_sym, y)end
37
40
  end
38
41
  end
39
42
 
40
43
  class NilClass
41
44
  def =~(value)
42
- value == nil
45
+ value.nil?
43
46
  end
44
47
 
45
- def +(value)
46
- value
48
+ def +(other)
49
+ other
47
50
  end
48
51
 
49
52
  def <<(value)
50
- [ value ]
53
+ [value]
51
54
  end
52
55
 
53
56
  def empty?
@@ -57,59 +60,58 @@ class NilClass
57
60
  def to_i
58
61
  0
59
62
  end
60
- alias :ord :to_i
63
+ alias ord to_i
61
64
 
62
65
  def size
63
66
  0
64
67
  end
65
68
 
66
- def <=>(value)
69
+ def <=>(_other)
67
70
  -1
68
71
  end
69
72
  end
70
73
 
71
-
72
74
  class Array
73
75
  def purge
74
- self.compact.delete_if {|x| x.empty? }
76
+ compact.delete_if { |x| x.empty? }
75
77
  end
76
78
 
77
79
  def >>(value = nil)
78
80
  value ? delete(value) : shift
79
81
  end
80
82
 
81
- alias :__get__ :[]
83
+ alias __get__ []
82
84
  def [](index, *args)
83
- return __get__(index.to_i, *args) if index.class == String and index =~ /^\d+$/
85
+ return __get__(index.to_i, *args) if index.instance_of?(String) and index =~ /^\d+$/
86
+
84
87
  __get__(index, *args)
85
88
  end
86
89
 
87
- alias :__set__ :[]=
90
+ alias __set__ []=
88
91
  def []=(index, value, *args)
89
- return __set__(index.to_i, value, *args) if index.class == String and index =~ /^\d+$/
92
+ return __set__(index.to_i, value, *args) if index.instance_of?(String) and index =~ /^\d+$/
93
+
90
94
  __set__(index, value, *args)
91
95
  end
92
96
  end
93
97
 
94
98
  class String
95
- def -(str)
96
- #TODO make smart search for match in the 'str', when only last subpart matched to 'self'
97
- len = self.size
99
+ def -(other)
100
+ # TODO: make smart search for match in the 'str', when only last subpart matched to 'self'
101
+ len = size
98
102
  bc = ec = nil
99
103
  (0...len).each do |idx|
100
- break bc = idx if self[idx] == str[0]
104
+ break bc = idx if self[idx] == other[0]
101
105
  end
102
- ((bc + 1)...len).each do |idx|
103
- break ec = idx if self[idx] != str[idx - bc]
104
- end if bc
105
- (not bc) ? self.clone : (not ec) ? self[0, bc] : self[0, bc] + self[ec, len - ec]
106
+ ((bc + 1)...len).each do |idx| break ec = idx if self[idx] != other[idx - bc]end if bc
107
+ bc ? ec ? self[0, bc] + self[ec, len - ec] : self[0, bc] : clone
106
108
  end
107
109
 
108
- alias :__match__ :=~
110
+ alias __match__ =~
109
111
  def =~(value)
110
- if value.class == String
112
+ if value.instance_of?(String)
111
113
  self == value
112
- elsif value.class == Regexp
114
+ elsif value.instance_of?(Regexp)
113
115
  value =~ self
114
116
  else
115
117
  __match__(value)
@@ -117,14 +119,14 @@ class String
117
119
  end
118
120
 
119
121
  def rmatch(value)
120
- self == value || self =~ /^\/([^\/]+)/ && value =~ /#{$1}/
122
+ self == value || self =~ %r{^/([^/]+)} && value =~ /#{Regexp.last_match(1)}/
121
123
  end
122
124
 
123
125
  def hexdump
124
- res= ''
126
+ res = ''
125
127
  i = 0
126
- self.each_byte do |byte|
127
- res << sprintf("%.2X ", byte)
128
+ each_byte do |byte|
129
+ res << format('%.2X ', byte)
128
130
  i += 1
129
131
  res << "\n" if i % 16 == 0
130
132
  end
@@ -133,13 +135,13 @@ class String
133
135
  end
134
136
 
135
137
  class Hash
136
- def |(inval)
137
- res = self.dup
138
- inval.each_pair do |key, val|
139
- if val.class == res[key].class
140
- if val.class == Hash
141
- res[key] |= inval[key]
142
- elsif val.class == Array
138
+ def |(other)
139
+ res = dup
140
+ other.each_pair do |key, val|
141
+ if val.instance_of?(res[key].class)
142
+ if val.instance_of?(Hash)
143
+ res[key] |= other[key]
144
+ elsif val.instance_of?(Array)
143
145
  res[key].concat val
144
146
  else
145
147
  res[key] = val
@@ -157,19 +159,17 @@ class Hash
157
159
 
158
160
  def reverse
159
161
  h = {}
160
- self.each_pair do |key, value|
162
+ each_pair do |key, value|
161
163
  if h.key? value
162
- if h[value].class == Array
163
- h[value] << key
164
- else
165
- h[value] = [ h[value], key ]
166
- end
164
+ if h[value].instance_of?(Array)
165
+ h[value] << key
166
+ else
167
+ h[value] = [h[value], key]
168
+ end
167
169
  else
168
- h[value] = key
170
+ h[value] = key
169
171
  end
170
172
  end
171
173
  h
172
174
  end
173
175
  end
174
-
175
-
data/lib/rdoba/debug.rb CHANGED
@@ -1,10 +1,12 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
- STDERR.puts "Warning: the module has kept only for backward compatibility\n" \
4
- "Please use 'rdoba :log' form instead"
3
+ warn "Warning: the module has kept only for backward compatibility\n" \
4
+ "Please use 'rdoba :log' form instead"
5
5
 
6
6
  require 'rdoba/log'
7
7
 
8
8
  module Rdoba
9
- def self.debug options = {}
10
- Rdoba.log options ; end ; end
9
+ def self.debug(options = {})
10
+ Rdoba.log options
11
+ end
12
+ end
data/lib/rdoba/deploy.rb CHANGED
@@ -1,74 +1,80 @@
1
1
  #!/usr/bin/ruby -KU
2
- #coding:utf-8
2
+ # frozen_string_literal: true
3
3
 
4
4
  require 'rdoba/common'
5
5
 
6
6
  class Hash
7
-
8
7
  def deploy!(vars = {})
9
- self.replace deploy(vars)
10
- # TODO add variable copy
8
+ replace deploy(vars)
9
+ # TODO: add variable copy
11
10
  end
12
11
 
13
12
  def deploy(vars = {})
14
13
  res = {}
15
14
 
16
- self.keys.sort do |x,y|
17
- if x =~ /=$/
18
- y =~ /=$/ ? x <=> y : -1
15
+ keys.sort do |x, y|
16
+ if /=$/.match?(x)
17
+ /=$/.match?(y) ? x <=> y : -1
19
18
  else
20
- y !~ /=$/ ? x <=> y : 1
19
+ /=$/.match?(y) ? 1 : x <=> y
21
20
  end
22
21
  end.each do |key|
23
-
24
22
  if key =~ /(.*)=$/
25
- vars[$1] = self[key]
26
- next
27
-
23
+ vars[Regexp.last_match(1)] = self[key]
24
+ next
28
25
  elsif key =~ /(.*)@$/
29
- sym = $1
30
- eval "res.class.co( :attr_accessor, :#{sym})"
31
- eval "res.#{sym} = self[key]"
32
- next
33
-
26
+ sym = Regexp.last_match(1)
27
+ eval "res.class.co( :attr_accessor, :#{sym})"
28
+ eval "res.#{sym} = self[key]"
29
+ next
34
30
  elsif key =~ /^%([^%].*)/
35
- next $stderr.puts "Warning: undefined variable " +
36
- "#{$1.inspect} found. Ignoring..." unless vars.key?($1)
37
- var = vars[$1].dup
38
- if var.class == Hash
39
- res |= var.deploy(vars)
40
- elsif var.class == String
41
- res[var] = nil
42
- else
43
- raise "Undeployable hash #{$1} value class #{var.class}"
44
- end
45
- next
31
+ unless vars.key?(Regexp.last_match(1))
32
+ next warn 'Warning: undefined variable ' + "#{Regexp.last_match(1).inspect} found. Ignoring..."
33
+ end
46
34
 
35
+ var = vars[Regexp.last_match(1)].dup
36
+ if var.instance_of?(Hash)
37
+ res |= var.deploy(vars)
38
+ elsif var.instance_of?(String)
39
+ res[var] = nil
40
+ else
41
+ raise "Undeployable hash #{Regexp.last_match(1)} value class #{var.class}"
42
+ end
43
+ next
47
44
  elsif key =~ /^%%(.*)/
48
- key.replace $1.to_s
45
+ key.replace Regexp.last_match(1).to_s
49
46
  end
50
47
 
51
48
  def deploy_value(value, vars)
52
- case value.class.to_sym
53
- when :String
54
- if value =~ /^%([^%].*)/
55
- begin; vars[$1].deploy(vars); rescue; nil end
56
- elsif value =~ /(.*)%([A-Za-z0-9_А-я]+)(.*)/
57
- a = [ $1.to_s, $2.to_s, $3.to_s ]
58
- a[1] = begin; vars[a[1]].deploy(vars).to_s; rescue; vars[a[1]] end
59
- a.join
60
- else
61
- value
62
- end
63
- when :Hash
64
- value.deploy(vars)
65
- when :Array
66
- value.map do |sub|
67
- deploy_value(sub, vars)
68
- end
69
- else
70
- value
71
- end
49
+ case value.class.to_sym
50
+ when :String
51
+ if value =~ /^%([^%].*)/
52
+ begin
53
+ vars[Regexp.last_match(1)].deploy(vars)
54
+ rescue StandardError
55
+ nil
56
+ end
57
+ elsif value =~ /(.*)%([A-Za-z0-9_А-я]+)(.*)/
58
+ a = [Regexp.last_match(1).to_s, Regexp.last_match(2).to_s, Regexp.last_match(3).to_s]
59
+ a[1] =
60
+ begin
61
+ vars[a[1]].deploy(vars).to_s
62
+ rescue StandardError
63
+ vars[a[1]]
64
+ end
65
+ a.join
66
+ else
67
+ value
68
+ end
69
+ when :Hash
70
+ value.deploy(vars)
71
+ when :Array
72
+ value.map do |sub|
73
+ deploy_value(sub, vars)
74
+ end
75
+ else
76
+ value
77
+ end
72
78
  end
73
79
 
74
80
  value = self[key]
@@ -77,4 +83,3 @@ class Hash
77
83
  res
78
84
  end
79
85
  end
80
-
data/lib/rdoba/dup.rb CHANGED
@@ -1,64 +1,64 @@
1
1
  #!/usr/bin/ruby -KU
2
- #coding:utf-8
2
+ # frozen_string_literal: true
3
3
 
4
4
  class Array
5
- alias :__dup__ :dup
5
+ alias __dup__ dup
6
6
  def dup(opts = {})
7
- if (opts.class == Hash ? opts.key?(:recursive) : opts.to_s.to_sym == :recursive)
7
+ if opts.instance_of?(Hash) ? opts.key?(:recursive) : opts.to_s.to_sym == :recursive
8
8
  res = []
9
9
 
10
10
  def sub_dup(value)
11
- if value.class.to_s =~ /(Hash|Array)/
12
- value.dup(:recursive)
13
- else
14
- begin
15
- value.dup
16
- rescue
17
- new = value
18
- end
19
- end
11
+ if /(Hash|Array)/.match?(value.class.to_s)
12
+ value.dup(:recursive)
13
+ else
14
+ begin
15
+ value.dup
16
+ rescue StandardError
17
+ new = value
18
+ end
19
+ end
20
20
  end
21
21
 
22
- self.each do |value| res << sub_dup(value) end
22
+ each do |value|
23
+ res << sub_dup(value)
24
+ end
23
25
 
24
26
  res
25
27
  elsif opts.empty?
26
28
  __dup__
27
29
  else
28
- raise "Unsupported option(s): #{opts.class == Hash ? opts.keys.join(', ') : opts}"
30
+ raise "Unsupported option(s): #{opts.instance_of?(Hash) ? opts.keys.join(', ') : opts}"
29
31
  end
30
32
  end
31
-
32
33
  end
33
34
 
34
35
  class Hash
35
- alias :__dup__ :dup
36
+ alias __dup__ dup
36
37
  def dup(opts = {})
37
- if (opts.class == Hash ? opts.key?(:recursive) : opts.to_s.to_sym == :recursive)
38
+ if opts.instance_of?(Hash) ? opts.key?(:recursive) : opts.to_s.to_sym == :recursive
38
39
  res = {}
39
40
 
40
41
  def sub_dup(value)
41
- if value.class.to_s =~ /(Hash|Array)/
42
- value.dup(:recursive)
43
- else
44
- begin
45
- value.dup
46
- rescue
47
- new = value
48
- end
49
- end
42
+ if /(Hash|Array)/.match?(value.class.to_s)
43
+ value.dup(:recursive)
44
+ else
45
+ begin
46
+ value.dup
47
+ rescue StandardError
48
+ new = value
49
+ end
50
+ end
50
51
  end
51
52
 
52
- self.each do |key, value| res[ sub_dup(key) ] = sub_dup(value) end
53
+ each do |key, value|
54
+ res[sub_dup(key)] = sub_dup(value)
55
+ end
53
56
 
54
57
  res
55
58
  elsif opts.empty?
56
59
  __dup__
57
60
  else
58
- raise "Unsupported option(s): #{opts.class == Hash ? opts.keys.join(', ') : opts}"
61
+ raise "Unsupported option(s): #{opts.instance_of?(Hash) ? opts.keys.join(', ') : opts}"
59
62
  end
60
63
  end
61
-
62
64
  end
63
-
64
-
data/lib/rdoba/fe.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/ruby -KU
2
+ # frozen_string_literal: true
2
3
 
3
4
  class String
4
5
  def fe
@@ -6,13 +7,13 @@ class String
6
7
  self
7
8
  else
8
9
  return self unless Encoding.default_internal
9
- if self.frozen?
10
- self.dup.force_encoding(Encoding.default_internal || 'UTF-8').freeze
10
+
11
+ if frozen?
12
+ dup.force_encoding(Encoding.default_internal || 'UTF-8').freeze
11
13
  else
12
- self.force_encoding(Encoding.default_internal || 'UTF-8')
14
+ force_encoding(Encoding.default_internal || 'UTF-8')
13
15
  end
14
16
  end
15
17
  end
16
- alias :fenc :fe
18
+ alias fenc fe
17
19
  end
18
-
data/lib/rdoba/gem.rb CHANGED
@@ -1,36 +1,40 @@
1
1
  #!/usr/bin/ruby -KU
2
- #encoding:utf-8
2
+ # frozen_string_literal: true
3
3
 
4
4
  require 'rbconfig'
5
5
 
6
6
  module Rdoba
7
- def self.gemroot gemname = nil, path = ''
8
- if !gem
9
- raise "Undefined gem name" ; end
10
- g = Gem::Specification.find_by_name( gemname )
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
- def self.os
15
- @@os ||= (
16
- host_os = RbConfig::CONFIG['host_os']
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
@@ -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 = 1
9
- Key = 2
10
- Value = 3
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 | self.keys).each do |key|
17
- if self.has_key? key
18
- case spec
19
- when Hash::Each::General
20
- yield key, self[key]
21
- when Hash::Each::Pair
22
- yield key, self[key]
23
- when Hash::Each::Key
24
- yield key
25
- when Hash::Each::Value
26
- yield self[key]
27
- end
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; self
42
+ @order = nil
43
+ self
42
44
  end
43
45
 
44
- alias :__each__ :each
45
- alias :__each_pair__ :each_pair
46
- alias :__each_key__ :each_key
47
- alias :__each_value__ :each_value
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
-