rmtools 2.3.6 → 2.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -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::FALSE
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 "lambda {#{string}}").string = string
19
+ (proc = (binding || Kernel).eval "proc {#{string}}").string = string
20
20
  proc
21
21
  end
22
22
 
@@ -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
- throw_no method
13
+ super
19
14
  end
20
15
  end
21
16
 
@@ -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 !a.b
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 !m or m.path =~ IgnoreFiles
40
- nil
41
- else
41
+ if m and m.path !~ IgnoreFiles
42
42
  step = a[i]
43
- if m.block_level # > 1.9
44
- step = step.sub(/block (\(\d+ levels\) )?in/, '{'+m.block_level+'}')
45
- end
46
- if m and m.func and m2 and [m.path, m.line] == [m2.path, m2.line]
47
- steps << " -> `#{'{'+m.block_level+'} ' if m.block_level}#{m.func}'"
48
- elsif m and m.line != 0 and line = RMTools.highlighted_line(m.path, m.line)
49
- bt << "#{step}#{steps.join}\n#{line}"
50
- steps = []
51
- else bt << step
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
- # analogue to String#>>
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, :instance_reader => false
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
@@ -17,6 +17,7 @@ module ObjectSpace
17
17
  nil
18
18
  end
19
19
  end
20
+ alias [] find
20
21
 
21
22
  end
22
23
  end
@@ -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)).b
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"
@@ -76,6 +76,10 @@ class String
76
76
  replace ansi from_encoding
77
77
  end
78
78
 
79
+ def is_utf!(utf='UTF-8')
80
+ force_encoding utf
81
+ end
82
+
79
83
  end
80
84
 
81
85
 
@@ -1,5 +1,9 @@
1
1
  # encoding: utf-8
2
2
  class String
3
+
4
+ def -(pattern)
5
+ gsub pattern, ''
6
+ end
3
7
 
4
8
  def inline
5
9
  index("\n").nil?
@@ -50,7 +50,7 @@ class String
50
50
  return [self] if len <= 0
51
51
  str = dup
52
52
  arr = []
53
- while str.b
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.b or buf.b
88
- if terminator and blocks.b and (
87
+ while !words.empty? or !buf.empty?
88
+ if terminator and !blocks.empty?
89
89
  buf_add = if terminator == :syntax
90
- split_by_syntax blocks[-1], maxlen, buf.size
91
- else blocks[-1][term_re]
92
- end.b)
93
- if buf_add == blocks[-1]
94
- blocks.pop
95
- else blocks[-1] = blocks[-1][0...-buf_add.size]
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
- while words.b
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
@@ -1,3 +1,3 @@
1
1
  module RMTools
2
- VERSION = '2.3.6'
2
+ VERSION = '2.4.0'
3
3
  end
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
- spec.add_runtime_dependency "activesupport"
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.3.6
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-05-29 00:00:00.000000000 Z
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