rmtools 2.3.6 → 2.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +11 -1
- data/ext/rmtools.cpp +560 -560
- data/ext/rmtools.h +161 -161
- data/lib/rmtools/console/coloring.rb +1 -1
- data/lib/rmtools/conversions/enum.rb +1 -1
- data/lib/rmtools/conversions/json.rb +3 -3
- data/lib/rmtools/core/arguments.rb +0 -1
- data/lib/rmtools/core/b.rb +4 -2
- data/lib/rmtools/core/js.rb +5 -2
- data/lib/rmtools/core/numeric.rb +15 -7
- data/lib/rmtools/core/proc.rb +2 -2
- data/lib/rmtools/core/symbol.rb +1 -6
- data/lib/rmtools/dev/binding.rb +1 -1
- data/lib/rmtools/dev/highlight.rb +14 -0
- data/lib/rmtools/dev/trace_format.rb +18 -13
- data/lib/rmtools/enumerable/array.rb +2 -1
- data/lib/rmtools/enumerable/array_iterators.rb +13 -2
- data/lib/rmtools/enumerable/object_space.rb +1 -0
- data/lib/rmtools/fs/tools.rb +1 -1
- data/lib/rmtools/lang/ansi.rb +4 -0
- data/lib/rmtools/text/string_simple.rb +4 -0
- data/lib/rmtools/text/string_split.rb +15 -11
- data/lib/rmtools/version.rb +1 -1
- data/rmtools.gemspec +2 -6
- metadata +6 -49
- data/lib/rmtools/conversions/numeric.rb +0 -36
data/lib/rmtools/core/proc.rb
CHANGED
@@ -3,7 +3,7 @@ class Proc
|
|
3
3
|
NULL = lambda {|*x|} unless defined? Proc::NULL
|
4
4
|
TRUE = lambda {|*x| true} unless defined? Proc::TRUE
|
5
5
|
FALSE = lambda {|*x| false} unless defined? Proc::FALSE
|
6
|
-
SELF = lambda {|x| x} unless defined? Proc::
|
6
|
+
SELF = lambda {|x| x} unless defined? Proc::SELF
|
7
7
|
attr_accessor :string
|
8
8
|
|
9
9
|
def when
|
@@ -16,7 +16,7 @@ class Proc
|
|
16
16
|
class << self
|
17
17
|
|
18
18
|
def eval string, binding=nil
|
19
|
-
(proc = (binding || Kernel).eval "
|
19
|
+
(proc = (binding || Kernel).eval "proc {#{string}}").string = string
|
20
20
|
proc
|
21
21
|
end
|
22
22
|
|
data/lib/rmtools/core/symbol.rb
CHANGED
@@ -1,21 +1,16 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
class Symbol
|
3
3
|
|
4
|
-
def +(str)
|
5
|
-
to_s + str
|
6
|
-
end
|
7
|
-
|
8
4
|
def split(splitter='_')
|
9
5
|
to_s.split splitter
|
10
6
|
end
|
11
7
|
alias :/ :split
|
12
8
|
|
13
|
-
alias :throw_no :method_missing
|
14
9
|
def method_missing(method, *args, &block)
|
15
10
|
if ''.respond_to? method
|
16
11
|
to_s.__send__ method, *args, &block
|
17
12
|
else
|
18
|
-
|
13
|
+
super
|
19
14
|
end
|
20
15
|
end
|
21
16
|
|
data/lib/rmtools/dev/binding.rb
CHANGED
@@ -20,7 +20,7 @@ class Binding
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def inspect_class_variables
|
23
|
-
vars = self.eval('self.class.class_variables') # ['@@a', '@@b']
|
23
|
+
vars = self.eval('(self.is_a?(Module) ? self : self.class).class_variables') # ['@@a', '@@b']
|
24
24
|
if vars and vars.any?
|
25
25
|
values = self.eval "{#{vars.map {|v| "'#{v}'=>defined?(#{v})&&#{v}"} * ','}}" # ["@@a's value", "@@b's value"]
|
26
26
|
#Hash[vars.zip(values)]
|
@@ -29,4 +29,18 @@ class Proc
|
|
29
29
|
"#{to_s}#{@string ? ': '+Painter.green(@string) : source_location && ": \n"+RMTools.highlighted_line(*source_location)}"
|
30
30
|
end
|
31
31
|
|
32
|
+
end
|
33
|
+
|
34
|
+
if RUBY_VERSION > '1.9'
|
35
|
+
class Method
|
36
|
+
def inspect
|
37
|
+
"#{to_s}: \n#{RMTools.highlighted_line(*source_location)}"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
class UnboundMethod
|
42
|
+
def inspect
|
43
|
+
"#{to_s}: \n#{RMTools.highlighted_line(*source_location)}"
|
44
|
+
end
|
45
|
+
end
|
32
46
|
end
|
@@ -28,27 +28,32 @@ module RMTools
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def format_trace(a)
|
31
|
-
return [] if
|
31
|
+
return [] if a.empty?
|
32
|
+
|
32
33
|
bt, steps, i = [], [], 0
|
33
34
|
m = a[0].parse:caller
|
34
35
|
# seems like that bug is fixed for now
|
35
36
|
#m.line -= 1 if m and m.file =~ /\.haml$/
|
37
|
+
|
36
38
|
while i < a.size
|
37
39
|
m2 = a[i+1] && a[i+1].parse(:caller)
|
38
40
|
#m2.line -= 1 if m2 and m2.file =~ /\.haml$/
|
39
|
-
if
|
40
|
-
nil
|
41
|
-
else
|
41
|
+
if m and m.path !~ IgnoreFiles
|
42
42
|
step = a[i]
|
43
|
-
if
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
43
|
+
if step["\n"] # already formatted
|
44
|
+
bt << step
|
45
|
+
else
|
46
|
+
if m.block_level # > 1.9
|
47
|
+
step = step.sub(/block (\(\d+ levels\) )?in/, '{'+m.block_level+'}')
|
48
|
+
end
|
49
|
+
if m and m.func and m2 and [m.path, m.line] == [m2.path, m2.line]
|
50
|
+
steps << " -> `#{'{'+m.block_level+'} ' if m.block_level}#{m.func}'"
|
51
|
+
elsif m and m.line != 0 and line = RMTools.highlighted_line(m.path, m.line)
|
52
|
+
bt << "#{step}#{steps.join}\n#{line}"
|
53
|
+
steps = []
|
54
|
+
else
|
55
|
+
bt << step
|
56
|
+
end
|
52
57
|
end
|
53
58
|
end
|
54
59
|
i += 1
|
@@ -176,7 +176,7 @@ class Array
|
|
176
176
|
alias :order_by :sort_along_by
|
177
177
|
|
178
178
|
# concatenation
|
179
|
-
#
|
179
|
+
# analogy of String#>>
|
180
180
|
def >>(ary)
|
181
181
|
ary.replace(self + ary)
|
182
182
|
end
|
@@ -206,6 +206,7 @@ class Array
|
|
206
206
|
each_with_index.map(&block)
|
207
207
|
end
|
208
208
|
|
209
|
+
# yield every unique combination of two elements
|
209
210
|
def each_two
|
210
211
|
_end = size-1
|
211
212
|
self[0..-2].each_with_index {|u, i|
|
@@ -15,16 +15,19 @@ class Array
|
|
15
15
|
if respond_to? :mattr_reader
|
16
16
|
mattr_reader :iterators_names, :iterators_pattern
|
17
17
|
else
|
18
|
-
cattr_reader :iterators_names, :iterators_pattern, :
|
18
|
+
cattr_reader :iterators_names, :iterators_pattern, :instance_accessor => false
|
19
19
|
end
|
20
20
|
@@iterators_names = []
|
21
21
|
|
22
22
|
private
|
23
23
|
|
24
|
+
# It's here just because it's simplier and faster (40 times)
|
25
|
+
# than ActiveSupport's singularization.
|
26
|
+
# If you want to use latter one, run
|
27
|
+
# Array.use_active_support_singularize!
|
24
28
|
def simple_inplace_singularize!(noun)
|
25
29
|
noun.sub!(/(ss|[sc]h|[xo])es([=!?]?)$/, '\1\2') or
|
26
30
|
noun.sub!(/ies([=!?]?)$/, 'y\1') or
|
27
|
-
noun.sub!(/ves([=!?]?)$/, 'f\1') or
|
28
31
|
noun.sub!(/s([=!?]?)$/, '\1')
|
29
32
|
end
|
30
33
|
|
@@ -35,6 +38,14 @@ private
|
|
35
38
|
@@iterators_names |= name_or_list
|
36
39
|
@@iterators_pattern = %r{^(#{@@iterators_names*'|'})_([\w\d\_]+[!?]?)}
|
37
40
|
end
|
41
|
+
|
42
|
+
def use_active_support_singularize!
|
43
|
+
class_eval do
|
44
|
+
def simple_inplace_singularize!(noun)
|
45
|
+
ActiveSupport::Inflector.singularize noun
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
38
49
|
|
39
50
|
def fallback_to_clean_iterators!
|
40
51
|
class_eval do
|
data/lib/rmtools/fs/tools.rb
CHANGED
@@ -19,7 +19,7 @@ module RMTools
|
|
19
19
|
lines = []
|
20
20
|
strlen = 0
|
21
21
|
step = qty*100
|
22
|
-
while qty > 0 and (offset = size-strlen-step) >= 0 and (str = IO.read(file, step, offset)).
|
22
|
+
while qty > 0 and (offset = size-strlen-step) >= 0 and !(str = IO.read(file, step, offset)).empty?
|
23
23
|
i = str.index("\n") || str.size
|
24
24
|
strlen += step - i
|
25
25
|
new_lines = str[i+1..-1]/"\n"
|
data/lib/rmtools/lang/ansi.rb
CHANGED
@@ -50,7 +50,7 @@ class String
|
|
50
50
|
return [self] if len <= 0
|
51
51
|
str = dup
|
52
52
|
arr = []
|
53
|
-
|
53
|
+
until str.empty?
|
54
54
|
arr << str.slice!(0, len)
|
55
55
|
end
|
56
56
|
arr
|
@@ -84,17 +84,21 @@ class String
|
|
84
84
|
blocks = []
|
85
85
|
term_re = /[^#{terminator}]+\z/ if terminator and terminator != :syntax
|
86
86
|
words, buf = split(opts[:strips] ? ' ' : / /), nil
|
87
|
-
while words.
|
88
|
-
if terminator and blocks.
|
87
|
+
while !words.empty? or !buf.empty?
|
88
|
+
if terminator and !blocks.empty?
|
89
89
|
buf_add = if terminator == :syntax
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
90
|
+
split_by_syntax blocks[-1], maxlen, buf.size
|
91
|
+
else
|
92
|
+
blocks[-1][term_re]
|
93
|
+
end
|
94
|
+
if !buf_add.empty?
|
95
|
+
if buf_add == blocks[-1]
|
96
|
+
blocks.pop
|
97
|
+
else
|
98
|
+
blocks[-1] = blocks[-1][0...-buf_add.size]
|
99
|
+
end
|
100
|
+
buf = buf_add + buf
|
96
101
|
end
|
97
|
-
buf = buf_add + buf
|
98
102
|
end
|
99
103
|
if blocks.size == opts[:lines]
|
100
104
|
return sanitize_blocks! blocks, maxlen, opts
|
@@ -104,7 +108,7 @@ class String
|
|
104
108
|
blocks[-1] << buf
|
105
109
|
buf = nil
|
106
110
|
end
|
107
|
-
|
111
|
+
until words.empty?
|
108
112
|
buf = words.shift + ' '
|
109
113
|
break if blocks[-1].size + buf.size - 1 > maxlen
|
110
114
|
blocks[-1] << buf
|
data/lib/rmtools/version.rb
CHANGED
data/rmtools.gemspec
CHANGED
@@ -14,14 +14,10 @@ Gem::Specification.new do |spec|
|
|
14
14
|
spec.homepage = "https://github.com/tinbka/rmtools"
|
15
15
|
spec.license = "MIT"
|
16
16
|
|
17
|
-
spec.files = `git ls-files`.split
|
17
|
+
spec.files = `git ls-files`.split
|
18
18
|
# nonetheless, for this gem spec.files() returns [] after installation
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
-
|
22
|
-
|
21
|
+
# we want to overwrite some its methods
|
23
22
|
spec.extensions << 'ext/extconf.rb'
|
24
|
-
|
25
|
-
spec.add_development_dependency "bundler", "~> 1.3"
|
26
|
-
spec.add_development_dependency "rake"
|
27
23
|
end
|
metadata
CHANGED
@@ -1,57 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rmtools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sergey Baev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
12
|
-
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: activesupport
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - '>='
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '0'
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - '>='
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '0'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: bundler
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - ~>
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '1.3'
|
34
|
-
type: :development
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - ~>
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '1.3'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: rake
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - '>='
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '0'
|
48
|
-
type: :development
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - '>='
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '0'
|
11
|
+
date: 2014-08-21 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
55
13
|
description: RMTools is a collection of helpers for debug, text/array/file processing
|
56
14
|
and simply easing a coding process
|
57
15
|
email:
|
@@ -61,7 +19,7 @@ extensions:
|
|
61
19
|
- ext/extconf.rb
|
62
20
|
extra_rdoc_files: []
|
63
21
|
files:
|
64
|
-
- .gitignore
|
22
|
+
- ".gitignore"
|
65
23
|
- Gemfile
|
66
24
|
- LICENSE
|
67
25
|
- README.md
|
@@ -81,7 +39,6 @@ files:
|
|
81
39
|
- lib/rmtools/conversions/int.rb
|
82
40
|
- lib/rmtools/conversions/ip.rb
|
83
41
|
- lib/rmtools/conversions/json.rb
|
84
|
-
- lib/rmtools/conversions/numeric.rb
|
85
42
|
- lib/rmtools/conversions/string.rb
|
86
43
|
- lib/rmtools/core.rb
|
87
44
|
- lib/rmtools/core/aliases.rb
|
@@ -172,12 +129,12 @@ require_paths:
|
|
172
129
|
- lib
|
173
130
|
required_ruby_version: !ruby/object:Gem::Requirement
|
174
131
|
requirements:
|
175
|
-
- -
|
132
|
+
- - ">="
|
176
133
|
- !ruby/object:Gem::Version
|
177
134
|
version: '0'
|
178
135
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
179
136
|
requirements:
|
180
|
-
- -
|
137
|
+
- - ">="
|
181
138
|
- !ruby/object:Gem::Version
|
182
139
|
version: '0'
|
183
140
|
requirements: []
|
@@ -1,36 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
class Integer
|
3
|
-
|
4
|
-
def from_ip
|
5
|
-
self
|
6
|
-
end
|
7
|
-
|
8
|
-
def to_ip
|
9
|
-
"#{(self >> 24) & 0xff}.#{(self >> 16) & 0xff}.#{(self >> 8) & 0xff}.#{self & 0xff}"
|
10
|
-
end
|
11
|
-
|
12
|
-
def mask_ip(val)
|
13
|
-
if val < 0
|
14
|
-
maskv = 32+val
|
15
|
-
else
|
16
|
-
maskv = val
|
17
|
-
val = 32 - val
|
18
|
-
end
|
19
|
-
self - (self & 2**val - 1)
|
20
|
-
end
|
21
|
-
|
22
|
-
end
|
23
|
-
|
24
|
-
class Range
|
25
|
-
|
26
|
-
def mask_ip
|
27
|
-
i = nil
|
28
|
-
31.downto(12) {|i|
|
29
|
-
lm = last.mask_ip(i)
|
30
|
-
break if first.mask_ip(i) == lm and (last+1).mask_ip(i) != lm
|
31
|
-
i = nil
|
32
|
-
}
|
33
|
-
i || 32
|
34
|
-
end
|
35
|
-
|
36
|
-
end
|