cutter 0.8.1 → 0.8.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,7 +5,6 @@ class Object
5
5
  log_coloured sp, "------------------------------", color(:line)
6
6
  end
7
7
 
8
-
9
8
  def log_coloured sp, msg, color = :default
10
9
  message = sp + msg
11
10
  message = color != :default ? message.send(color) : message
@@ -33,6 +32,10 @@ module Cutter
33
32
  @colors ||= {:line => :blue,
34
33
  :time => :light_blue,
35
34
 
35
+ :message_name => :cyan,
36
+ :message_line => :cyan,
37
+ :total_line => :yellow,
38
+ :total_count => :yellow
36
39
  # Colors for #inspect!
37
40
  #:called_from => :light_magenta,
38
41
  #:class_name => :red,
@@ -24,26 +24,17 @@ class Object
24
24
  def inspect! *options, &block
25
25
  return true if Cutter::Inspection.quiet?
26
26
 
27
- def __colors
28
- Cutter::ColoredOutputs.colors_config
29
- end
30
-
31
- def to_cs obj
32
- color = __colors[obj] || :default
33
- color != :default ? to_s.send(color) : to_s
34
- end
35
-
36
27
  # Getting binding
37
28
  _binding = options.first if options.first.class == Binding
38
29
  raise ArgumentError, "Try inspect(binding) or inspect! {}", caller if (!block_given? && !_binding)
39
30
  _binding ||= block.binding
40
31
 
41
- # Want caller methods chain to be traced? - pass option :level to inspect!
42
32
  options = options.extract_options!
43
33
 
44
34
  max = options[:max]
45
35
  options.maximize_options! if max
46
-
36
+
37
+ # Want caller methods chain to be traced? - pass option :level to inspect!
47
38
  level = options[:level]
48
39
  _caller = caller
49
40
 
@@ -53,42 +44,43 @@ class Object
53
44
  method_name = eval('__method__', _binding)
54
45
  class_name = eval('self.class', _binding)
55
46
 
56
- puts "\n%s `%s' %s" % ['method:'.to_cs(:method), method_name.to_cs(:method_name), ('(maximal tracing)' if max)]
57
- puts " %s %s" % ['called from class:'.to_cs(:called_from), class_name.to_cs(:class_name)]
47
+ puts "\n%s `%s' %s" % ['method:'.__cs(:method), method_name.__cs(:method_name), ('(maximal tracing)' if max)]
48
+ puts " %s %s" % ['called from class:'.__cs(:called_from), class_name.__cs(:class_name)]
58
49
 
59
50
  # Local Variables
60
51
  lvb = eval('local_variables',_binding)
61
- puts " %s %s" % ['local_variables:'.to_cs(:lv), ("[]" if lvb.empty?)]
52
+ puts " %s %s" % ['local_variables:'.__cs(:lv), ("[]" if lvb.empty?)]
62
53
 
63
54
  lvb.map do |lv|
64
55
  local_variable = eval(lv.to_s, _binding)
65
- local_variable = (max ? local_variable.inspect : local_variable.to_real_string)
56
+ local_variable = (max ? local_variable.inspect : local_variable.__rs)
66
57
 
67
- puts " %s: %s" % [lv.to_cs(:lv_names), local_variable.to_cs(:lv_values)]
58
+ puts " %s: %s" % [lv.__cs(:lv_names), local_variable.__cs(:lv_values)]
68
59
  end if lvb
69
60
 
61
+ # Instance Variables
70
62
  ivb = eval('instance_variables',_binding)
71
63
 
72
- puts " %s %s" % ["instance_variables:".to_cs(:iv), ("[]" if ivb.empty?)]
64
+ puts " %s %s" % ["instance_variables:".__cs(:iv), ("[]" if ivb.empty?)]
73
65
 
74
66
  ivb.map do |iv|
75
67
  instance_variable = eval(iv.to_s, _binding)
76
- instance_variable = (max ? instance_variable.inspect : instance_variable.to_real_string)
68
+ instance_variable = (max ? instance_variable.inspect : instance_variable.__rs)
77
69
 
78
- puts " %s: %s" % [iv.to_cs(:iv_names), instance_variable.to_cs(:iv_values)]
70
+ puts " %s: %s" % [iv.__cs(:iv_names), instance_variable.__cs(:iv_values)]
79
71
  end if ivb
80
72
 
81
73
  # Self inspection
82
74
  begin
83
- puts " self inspection:".to_cs(:self_inspection)
84
- puts " %s" % self_inspection.to_cs(:self_inspection_trace)
75
+ puts " self inspection:".__cs(:self_inspection)
76
+ puts " %s" % self_inspection.__cs(:self_inspection_trace)
85
77
  end if self_inspection
86
78
 
87
79
  # Caller methods chain
88
80
  begin
89
- puts " caller methods: ".to_cs(:caller_methods)
81
+ puts " caller methods: ".__cs(:caller_methods)
90
82
  0.upto(level).each {|index|
91
- puts " %s" % _caller[index].to_cs(:caller_method)
83
+ puts " %s" % _caller[index].__cs(:caller_method)
92
84
  }
93
85
  end if level
94
86
 
@@ -97,19 +89,32 @@ class Object
97
89
  yield if block_given?
98
90
  end
99
91
 
92
+ protected
93
+
100
94
  def caller_method_name(level = 1)
101
95
  caller[level][/`([^']*)'/,1].to_sym
102
96
  end
103
97
 
104
- protected
105
-
106
98
  def maximize_options!
107
99
  self.merge!({:max => true, :inspect => true, :level => 2})
108
100
  end
109
101
 
110
- def to_real_string
102
+ # ("real string") Now used to print Symbols with colons
103
+ def __rs
111
104
  return ":#{self.to_s}" if self.class == Symbol
112
105
  self
113
106
  end
107
+
108
+ def __cs obj
109
+ color = __colors[obj] || :default
110
+ color != :default ? to_s.send(color) : to_s
111
+ end
112
+
113
+ private
114
+
115
+ def __colors
116
+ Cutter::ColoredOutputs.colors_config
117
+ end
118
+
114
119
  end
115
120
 
@@ -8,10 +8,6 @@ class Object
8
8
 
9
9
  def stamper name = nil, &block
10
10
 
11
- def log_time sp, msg
12
- log_coloured sp, msg, color(:time)
13
- end
14
-
15
11
  return if stamper_class.off?
16
12
  scope = stamper_class[name] || stamper_class[:default]
17
13
  scope.indent = stamper_class.last ? stamper_class.last.indent + 1 : 0
@@ -21,17 +17,23 @@ class Object
21
17
  if scope
22
18
  message = scope.label.values.first
23
19
  end
24
- spaces = " " * scope.indent
25
- line spaces
26
- log_coloured spaces, "~ START " << "#{message}"
20
+ spaces = " " * scope.indent
21
+ puts "\n"
22
+ log_coloured spaces, "#{message}", color(:message_name)
23
+ log_coloured spaces, "#{'-'*message.length}", color(:message_line)
24
+
27
25
  scope.time_initial = time_now
28
26
  yield scope
29
27
  scope.indent -= 1 if scope.indent > 0
30
28
  stamper_class.pop
31
29
  time_passed = time_now - scope.time_initial
32
- log_coloured spaces, "~ END " << "#{message}"
33
- log_time spaces, "[#{time_passed}ms]"
34
- line spaces
30
+
31
+ tps = "#{time_passed}ms"
32
+ offset = message.length - tps.length
33
+ offset = 0 if offset < 0
34
+ log_coloured spaces, "#{'-'*message.length}", color(:total_line)
35
+ log_coloured spaces + "#{' ' * (offset)}", tps, color(:total_count)
36
+ puts "\n"
35
37
  end
36
38
 
37
39
  private
@@ -106,7 +108,7 @@ module Cutter
106
108
  message = messages[lbl] || lbl.to_s.humanize
107
109
  time_passed = time_now - time_initial
108
110
  print " " * nindent
109
- printf("~ stamp: %7d ms #{message}\n", time_passed)
111
+ printf("stamp: %7d ms #{message}\n", time_passed)
110
112
  end
111
113
 
112
114
  module ClassMethods
@@ -151,5 +153,5 @@ module Cutter
151
153
  end
152
154
  end
153
155
 
154
- Cutter::Stamper.scope :default => nil do |default|
156
+ Cutter::Stamper.scope :default => "no name" do |default|
155
157
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: cutter
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.8.1
5
+ version: 0.8.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - stanislaw
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-08-08 00:00:00 +03:00
13
+ date: 2011-08-09 00:00:00 +03:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -100,7 +100,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
100
100
  requirements:
101
101
  - - ">="
102
102
  - !ruby/object:Gem::Version
103
- hash: -666484749
103
+ hash: -202257491
104
104
  segments:
105
105
  - 0
106
106
  version: "0"