rmtools 1.1.11 → 1.2.0

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 (53) hide show
  1. data/Manifest.txt +16 -21
  2. data/README.txt +17 -5
  3. data/Rakefile +1 -1
  4. data/lib/rmtools/console/coloring.rb +58 -42
  5. data/lib/rmtools/console/highlight.rb +1 -1
  6. data/lib/rmtools/core/arguments.rb +7 -4
  7. data/lib/rmtools/core/js.rb +6 -5
  8. data/lib/rmtools/core/kernel.rb +37 -1
  9. data/lib/rmtools/core/module.rb +1 -1
  10. data/lib/rmtools/{debug → dev}/binding.rb +6 -6
  11. data/lib/rmtools/{experimental → dev}/blackhole.rb +0 -0
  12. data/lib/rmtools/dev/code_reader.rb +431 -0
  13. data/lib/rmtools/{debug → dev}/highlight.rb +2 -2
  14. data/lib/rmtools/{debug → dev}/logging.rb +44 -47
  15. data/lib/rmtools/{debug → dev}/observing.rb +8 -2
  16. data/lib/rmtools/dev/present.rb +63 -0
  17. data/lib/rmtools/{debug → dev}/timer.rb +3 -3
  18. data/lib/rmtools/{debug → dev}/trace_format.rb +3 -9
  19. data/lib/rmtools/{debug → dev}/traceback.rb +1 -1
  20. data/lib/rmtools/{debug.rb → dev.rb} +0 -0
  21. data/lib/rmtools/dev_min.rb +2 -0
  22. data/lib/rmtools/enumerable/array.rb +12 -1
  23. data/lib/rmtools/enumerable/array_iterators.rb +5 -3
  24. data/lib/rmtools/enumerable/common.rb +0 -2
  25. data/lib/rmtools/enumerable/hash.rb +10 -4
  26. data/lib/rmtools/enumerable/object_space.rb +11 -9
  27. data/lib/rmtools/enumerable/range.rb +21 -0
  28. data/lib/rmtools/fs/tools.rb +6 -2
  29. data/lib/rmtools/install.rb +4 -2
  30. data/lib/rmtools/lang/cyrillic.rb +2 -2
  31. data/lib/rmtools/lang/{shortcuts.rb → helpers.rb} +0 -0
  32. data/lib/rmtools/load.rb +1 -1
  33. data/lib/rmtools/text/regexp.rb +74 -0
  34. data/lib/rmtools/text/string_rtl.rb +28 -0
  35. data/lib/rmtools/text/string_scanner.rb +19 -9
  36. data/lib/rmtools/text/string_simple.rb +11 -3
  37. data/lib/rmtools/text/string_split.rb +1 -5
  38. data/lib/rmtools/xml/node.rb +1 -1
  39. data/lib/rmtools/xml/string.rb +2 -2
  40. data/lib/rmtools.rb +1 -8
  41. data/lib/rmtools_dev.rb +6 -0
  42. metadata +21 -26
  43. data/lib/rmtools/debug/present.rb +0 -39
  44. data/lib/rmtools/debug_notrace.rb +0 -2
  45. data/lib/rmtools/experimental/dumps.rb +0 -29
  46. data/lib/rmtools/experimental/numeric.rb +0 -54
  47. data/lib/rmtools/experimental/rails_backtrace.rb +0 -30
  48. data/lib/rmtools/experimental/string.rb +0 -56
  49. data/lib/rmtools/experimental/tree.rb +0 -72
  50. data/lib/rmtools/experimental.rb +0 -2
  51. data/lib/rmtools_nodebug.rb +0 -3
  52. data/lib/rmtools_notrace.rb +0 -7
  53. data/lib/rmtools_safe.rb +0 -2
data/Manifest.txt CHANGED
@@ -9,6 +9,16 @@ lib/rmtools/fs/dir.rb
9
9
  lib/rmtools/fs/tools.rb
10
10
  lib/rmtools/ip/numeric.rb
11
11
  lib/rmtools/ip/string.rb
12
+ lib/rmtools/dev/present.rb
13
+ lib/rmtools/dev/blackhole.rb
14
+ lib/rmtools/dev/observing.rb
15
+ lib/rmtools/dev/traceback.rb
16
+ lib/rmtools/dev/binding.rb
17
+ lib/rmtools/dev/logging.rb
18
+ lib/rmtools/dev/trace_format.rb
19
+ lib/rmtools/dev/highlight.rb
20
+ lib/rmtools/dev/timer.rb
21
+ lib/rmtools/dev/code_reader.rb
12
22
  lib/rmtools/xml/xpath.rb
13
23
  lib/rmtools/xml/string.rb
14
24
  lib/rmtools/xml/libxml.rb
@@ -29,7 +39,7 @@ lib/rmtools/core/deprecation.rb
29
39
  lib/rmtools/core/regexp.rb
30
40
  lib/rmtools/core/class.rb
31
41
  lib/rmtools/core/proc.rb
32
- lib/rmtools/lang/shortcuts.rb
42
+ lib/rmtools/lang/helpers.rb
33
43
  lib/rmtools/lang/ansi.rb
34
44
  lib/rmtools/lang/regexp.rb
35
45
  lib/rmtools/lang/cyrillic.rb
@@ -40,8 +50,10 @@ lib/rmtools/rand/array.rb
40
50
  lib/rmtools/text/string_simple.rb
41
51
  lib/rmtools/text/string_scanner.rb
42
52
  lib/rmtools/text/textilize.rb
53
+ lib/rmtools/text/string_rtl.rb
43
54
  lib/rmtools/text/string_split.rb
44
55
  lib/rmtools/text/string_parse.rb
56
+ lib/rmtools/text/regexp.rb
45
57
  lib/rmtools/time/russian.rb
46
58
  lib/rmtools/time/global.rb
47
59
  lib/rmtools/rand.rb
@@ -50,20 +62,11 @@ lib/rmtools/console/printing.rb
50
62
  lib/rmtools/console/highlight.rb
51
63
  lib/rmtools/core.rb
52
64
  lib/rmtools/db.rb
53
- lib/rmtools/debug/present.rb
54
- lib/rmtools/debug/observing.rb
55
- lib/rmtools/debug/traceback.rb
56
- lib/rmtools/debug/binding.rb
57
- lib/rmtools/debug/logging.rb
58
- lib/rmtools/debug/trace_format.rb
59
- lib/rmtools/debug/highlight.rb
60
- lib/rmtools/debug/timer.rb
61
65
  lib/rmtools/fs.rb
62
66
  lib/rmtools/ip.rb
63
67
  lib/rmtools/lang.rb
64
68
  lib/rmtools/functional.rb
65
69
  lib/rmtools/load.rb
66
- lib/rmtools/experimental.rb
67
70
  lib/rmtools/install.rb
68
71
  lib/rmtools/functional/decorate.rb
69
72
  lib/rmtools/functional/fold.rb
@@ -71,8 +74,7 @@ lib/rmtools/functional/unfold.rb
71
74
  lib/rmtools/text.rb
72
75
  lib/rmtools/console.rb
73
76
  lib/rmtools/time.rb
74
- lib/rmtools/debug_notrace.rb
75
- lib/rmtools/debug.rb
77
+ lib/rmtools/dev.rb
76
78
  lib/rmtools/enumerable/common.rb
77
79
  lib/rmtools/enumerable/range.rb
78
80
  lib/rmtools/enumerable/hash.rb
@@ -80,21 +82,14 @@ lib/rmtools/enumerable/array.rb
80
82
  lib/rmtools/enumerable/object_space.rb
81
83
  lib/rmtools/enumerable/array_iterators.rb
82
84
  lib/rmtools/require.rb
83
- lib/rmtools/experimental/numeric.rb
84
- lib/rmtools/experimental/string.rb
85
- lib/rmtools/experimental/blackhole.rb
86
- lib/rmtools/experimental/tree.rb
87
- lib/rmtools/experimental/dumps.rb
88
- lib/rmtools/experimental/rails_backtrace.rb
89
85
  lib/rmtools/xml.rb
90
86
  lib/rmtools/conversions.rb
91
87
  lib/rmtools/conversions/string.rb
92
88
  lib/rmtools/conversions/enum.rb
93
89
  lib/rmtools/conversions/int.rb
94
90
  lib/rmtools/enumerable.rb
95
- lib/rmtools_notrace.rb
96
- lib/rmtools_safe.rb
97
- lib/rmtools_nodebug.rb
91
+ lib/rmtools/dev_min.rb
92
+ lib/rmtools_dev.rb
98
93
  ./Rakefile
99
94
  ./Manifest.txt
100
95
  ./License.txt
data/README.txt CHANGED
@@ -8,6 +8,22 @@ Methods for basic classes addon collection.
8
8
 
9
9
  == CHANGES
10
10
 
11
+ == Version 1.2.0
12
+
13
+ * Renamed debug/ to dev/, slightly restructured lib/rmtools/ and require handlers: requrie 'rmtools' for common applications and 'rmtools_dev' for irb and maybe dev environment
14
+ * Slightly extended StringScanner
15
+ * Proof of concept: Regexp reverse (wonder if someone did it earlier in Ruby)
16
+ * Kernel#whose? to find classes and/or modules knowing some method
17
+ * Method code lookup over all loaded libs (it can't handle evals yet), see dev/code_lookup.rb
18
+ * Coloring is now made by singleton `Painter' and have option for transparent coloring
19
+
20
+ === Version 1.1.14
21
+
22
+ * Added caller level option (:caller => <int>) for Logger
23
+ * Fixed trace formatting (for sure for this time)
24
+ * Array iterator #sum_<method> now takes argument for #sum as first argument
25
+ * Completed Binding#inspect_env components
26
+
11
27
  === Version 1.1.11
12
28
 
13
29
  * Fixed Hash#unify_keys for 1.9.2
@@ -16,13 +32,9 @@ Methods for basic classes addon collection.
16
32
 
17
33
  === Version 1.1.10
18
34
 
19
- * Some bugfixes for previous updates
20
-
21
- === Version 1.1.8
22
-
23
35
  * Deleted String#to_proc. It's anyway inconsistent and causes bug in ActiveRecord 3.0.5 Base#interpolate_and_sanitize_sql and potentially somewhere else
24
36
  * Solved problem with String#sub methods in 1.9: that's associated with String#to_hash in some mystic way. #to_hash is now #to_params
25
- * Completed Binding#inspect_env
37
+ * Some bugfixes for previous updates
26
38
 
27
39
  === Version 1.1.7
28
40
 
data/Rakefile CHANGED
@@ -2,7 +2,7 @@ require 'rake'
2
2
  require 'lib/rmtools/install'
3
3
  compile_manifest
4
4
 
5
- RMTOOLS_VERSION = '1.1.11'
5
+ RMTOOLS_VERSION = '1.2.0'
6
6
  begin
7
7
  require 'hoe'
8
8
  config = Hoe.spec 'rmtools' do
@@ -3,11 +3,7 @@ RMTools::require 'enumerable/hash'
3
3
 
4
4
  module RMTools
5
5
 
6
- class Coloring
7
- __init__
8
- method_defined? :b and undef_method :b
9
- method_defined? :p and undef_method :p
10
-
6
+ class Painter
11
7
  if !defined? ::BOLD
12
8
  BOLD = 1
13
9
  UNDERLINE = 4
@@ -30,45 +26,65 @@ module RMTools
30
26
  :b => 1, :u => 4, :gbg => 5, :bbg => 7
31
27
  }.unify_keys
32
28
  end
33
-
34
- def paint(str, num=nil, effect=nil)
35
- # default cmd.exe cannot into ANSI
36
- return str if ENV['ComSpec'] =~ /cmd(.exe)?$/
37
- num = Colors[num] if num.is String
38
- effect = Effects[effect] if effect.is String
39
- if num and effect
40
- "\e[#{effect};#{num}m#{str}\e[m"
41
- elsif effect
42
- "\e[#{effect}m#{str}\e[m"
43
- elsif num
44
- "\e[#{num}m#{str}\e[m"
45
- else str
46
- end
47
- end
48
-
49
- def method_missing(m, str)
50
- paint str, *(m.to_s/"_")
51
- end
52
-
53
- def clean str
54
- str.gsub(/\e\[.*?m/, '')
29
+
30
+ class << self
31
+ method_defined? :b and undef_method :b
32
+ method_defined? :p and undef_method :p
33
+
34
+ def paint(str, transparent, num=nil, effect=nil)
35
+ # default cmd.exe cannot into ANSI
36
+ str = str.to_s
37
+ return str if ENV['ComSpec'] =~ /cmd(.exe)?$/
38
+ if num.is String
39
+ num = Colors[num]
40
+ effect = Effects[num] if !num
41
+ end
42
+ effect = Effects[effect] if effect.is String
43
+ if num and effect
44
+ str = str.gsub("\e[m", "\e[m\e[#{effect};#{num}m") if transparent
45
+ "\e[#{effect};#{num}m#{str}\e[m"
46
+ elsif effect
47
+ str = str.gsub("\e[m", "\e[m\e[#{effect}m") if transparent
48
+ "\e[#{effect}m#{str}\e[m"
49
+ elsif num
50
+ str = str.gsub("\e[m", "\e[m\e[#{num}m") if transparent
51
+ "\e[#{num}m#{str}\e[m"
52
+ else str
53
+ end
54
+ end
55
+
56
+ # puts "words have one #{Painter.red_bold 'highlighted'} among them"
57
+ # <default>words have one <red>highlighted</red> among them</default>
58
+ # puts Painter.gray "words have one #{Painter.red_bold 'highlighted'} among them"
59
+ # <gray>words have one </gray><red>highlighted</red><default> among them</default>
60
+ # puts Painter.gray "words have one #{Painter.red_bold 'highlighted'} among them", true
61
+ # <gray>words have one <red>highlighted</red> among them</gray>
62
+ #
63
+ # Actually, transparent coloring is slower
64
+ def method_missing(m, str, transparent=false)
65
+ paint str, transparent, *(m.to_s/"_")
66
+ end
67
+
68
+ def clean str
69
+ str.gsub(/\e\[[\d;]*m/, '')
70
+ end
71
+
72
+ ['sub', 'gsub', 'sub!', 'gsub!'].each {|m|
73
+ class_eval %{
74
+ def #{m.sub'sub','hl'} str, pattern, color=:red_bold
75
+ str.#{m} pattern do |word|
76
+ if str[/^\\e\\[(\\d+(;\\d+)?)/]
77
+ "\\e[m\#{send(color, word)}\\e[\#$1m"
78
+ else
79
+ send(color, word)
80
+ end
81
+ end
82
+ end
83
+ }
84
+ }
85
+
55
86
  end
56
87
 
57
88
  end
58
89
 
59
- Painter = Coloring.new
60
- ['sub', 'gsub', 'sub!', 'gsub!'].each {|m|
61
- Coloring.module_eval "
62
- def #{m.sub('sub') {'hl'}} str, pattern, color=:red_bold
63
- str.#{m}(pattern) {|word| send color, word}
64
- end
65
- "
66
- module_eval "
67
- def #{m.sub('sub') {'hl'}} str, pattern, color=:red_bold
68
- str.#{m}(pattern) {|word| Painter.send color, word}
69
- end
70
- "
71
- # module_function m.to_sym
72
- }
73
-
74
90
  end
@@ -8,7 +8,7 @@ class String
8
8
  when Regexp; self =~ pat
9
9
  else raise TypeError, "pattern must be string or regexp"
10
10
  end
11
- puts RMTools.ghl(self[[idx-range, 0].max, 2*range], pat)
11
+ puts Painter.ghl(self[[idx-range, 0].max, 2*range], pat)
12
12
  end
13
13
 
14
14
  end
@@ -10,15 +10,18 @@ class Array
10
10
  # and get `a' from `'opts' hash
11
11
  def fetch_opts(defaults=[], opts={})
12
12
  if Hash === defaults
13
- opts = defaults
14
- defaults = []
15
- $log.warn "fetch_opts(<hash>) now changed"
13
+ opts, defaults = defaults, []
14
+ return_hash = true
15
+ $log.warn "fetch_opts(<hash>) now changed, if you want to jsut fetch hash options, use `opts = <hash>.merge(opts||{})' construction"
16
+ else
17
+ return_hash = false
16
18
  end
17
- opts &&= if self[-1].kind_of?(Hash) and !defaults[size-1].kind_of?(Hash)
19
+ opts &&= if Hash === self[-1] and !(Hash === defaults[size-1])
18
20
  opts.merge pop
19
21
  else
20
22
  opts.dup
21
23
  end
24
+ return opts if return_hash
22
25
  if defaults == :flags
23
26
  defauls = [:flags]
24
27
  end
@@ -1,6 +1,7 @@
1
1
  # encoding: utf-8
2
2
  # js hash getter/setter and string concat logic
3
3
  class Hash
4
+ alias :throw_no :method_missing
4
5
 
5
6
  # hash = {}
6
7
  # hash.abc = 123
@@ -10,14 +11,14 @@ class Hash
10
11
  # hash.unknown_function # => nil
11
12
  # hash[:def] = 456
12
13
  # hash.def # => 456
13
- def method_missing(met, *args)
14
- str = met.id2name
15
- if str[/=$/]
14
+ def method_missing(method, *args)
15
+ str = method.to_s
16
+ if str =~ /=$/
16
17
  self[str[0..-2]] = args[0]
17
18
  else
18
- raise NoMethodError, "undefined method `#{str}' for #{self}:#{(self.class)}" if !args.empty?
19
+ throw_no method if !args.empty? or str =~ /[!?]$/
19
20
  a = self[str]
20
- (a == default) ? self[met] : a
21
+ (a == default) ? self[method] : a
21
22
  end
22
23
  end
23
24
 
@@ -3,7 +3,7 @@ module Kernel
3
3
 
4
4
  # re-require
5
5
  def require!(file)
6
- %w{.rb .so .dll}.each {|ext| $".delete "#{file}#{ext}"}
6
+ ['.rb', '.so', '.dll', ''].each {|ext| $".delete "#{file}#{ext}"}
7
7
  require file
8
8
  end
9
9
 
@@ -26,4 +26,40 @@ module Kernel
26
26
  caller(0)[0] =~ /^#{file}:/
27
27
  end
28
28
 
29
+ def whose?(method, *opts)
30
+ opts = opts.get_opts [:flags], :ns => :public
31
+ checker = :"#{ns}_method_defined?"
32
+ if Array === method
33
+ methods = method.to_syms
34
+ else
35
+ methods = [method = method.to_sym]
36
+ end
37
+ if defined? ActiveSupport::JSON::CircularReferenceError
38
+ ActiveSupport::JSON.__send__ :remove_const, :CircularReferenceError
39
+ end
40
+ classes = {}
41
+
42
+ methods.each {|m|
43
+ classes[m] = {Object => true} if Object.send checker, m and (
44
+ !opts[:modules] or
45
+ Object.included_modules.select {|mod| (checker[m] ||= {})[mod] = true if mod.__send__ checker, m}.empty?
46
+ )
47
+ }
48
+ methods -= classes.keys
49
+ return classes.map_values {|h| h.keys} if methods.empty?
50
+
51
+ klass = opts[:modules] ? Module : Class
52
+ ObjectSpace.each_object {|o|
53
+ methods.each {|m| (classes[m] ||= {})[o] = true if o.name != '' and o.__send__ checker, m} if klass === o
54
+ }
55
+ classes.map_values! {|h|
56
+ if !opts[:descendants]
57
+ h.each {|c, b| h[c] = nil if (c.is Class and h.key? c.superclass) or (opts[:modules] and c.included_modules.find {|a| h.key? a})}
58
+ end
59
+ h.map {|c,b| b && c}.compact
60
+ }
61
+
62
+ Array === method ? classes : classes[method]
63
+ end
64
+
29
65
  end
@@ -26,7 +26,7 @@ class Module
26
26
  end
27
27
 
28
28
  def my_methods filter=//
29
- self.singleton_methods.sort!.grep(filter)
29
+ (self.singleton_methods - Object.singleton_methods).sort!.grep(filter)
30
30
  end
31
31
  alias personal_methods my_methods
32
32
 
@@ -1,6 +1,6 @@
1
1
  # encoding: utf-8
2
- RMTools::require 'debug/logging'
3
- RMTools::require 'debug/present'
2
+ RMTools::require 'dev/logging'
3
+ RMTools::require 'dev/present'
4
4
 
5
5
  class Binding
6
6
 
@@ -12,7 +12,7 @@ class Binding
12
12
 
13
13
  def inspect_instance_variables
14
14
  vars = self.eval('instance_variables') # ['@a', '@b']
15
- if !vars.empty?
15
+ if vars and vars.any?
16
16
  values = self.eval "[#{vars * ','}]" # ["@a's value", "@b's value"]
17
17
  Hash[vars.zip(values)]
18
18
  else {}
@@ -21,9 +21,9 @@ class Binding
21
21
 
22
22
  def inspect_class_variables
23
23
  vars = self.eval('self.class.class_variables') # ['@@a', '@@b']
24
- if !vars.empty?
25
- values = self.eval "[#{vars * ','}]" # ["@@a's value", "@@b's value"]
26
- Hash[vars.zip(values)]
24
+ if vars and vars.any?
25
+ values = self.eval "{#{vars.map {|v| "'#{v}'=>defined?(#{v})&&#{v}"} * ','}}" # ["@@a's value", "@@b's value"]
26
+ #Hash[vars.zip(values)]
27
27
  else {}
28
28
  end
29
29
  end
File without changes