lib/cutter/stamper.rb in cutter-0.8.6 vs lib/cutter/stamper.rb in cutter-0.8.7
- old
+ new
@@ -14,33 +14,45 @@
if scope
message = scope.label.values.first
end
spaces = " " * scope.indent
puts "\n"
- log_coloured spaces, "#{message}", color(:message_name)
- log_coloured spaces, "#{'-'*message.length}", color(:message_line)
+ log_coloured spaces, "#{message}", __color__(:message_name)
+ log_coloured spaces, "#{'-'*message.length}", __color__(:message_line)
scope.time_initial = time_now
+
+ self.class.send :define_method, :stamp do |*args|
+ scope.stamp args.first
+ end
+ self.class.send :alias_method, :stamp!, :stamp
+
yield scope
+
+ instance_eval do
+ undef :stamp if respond_to? :stamp
+ undef :stamp! if respond_to? :stamp!
+ end
+
scope.indent -= 1 if scope.indent > 0
stamper_class.pop
time_passed = time_now - scope.time_initial
-
+
tps = "#{time_passed}ms"
offset = message.length - tps.length
offset = 0 if offset < 0
- log_coloured spaces, "#{'-'*message.length}", color(:total_line)
- log_coloured spaces + "#{' ' * (offset)}", tps, color(:total_count)
+ log_coloured spaces, "#{'-'*message.length}", __color__(:total_line)
+ log_coloured spaces + "#{' ' * (offset)}", tps, __color__(:total_count)
puts "\n"
end
private
- def color type
+ def __color__ type
stamper_class.colors_config[type] if stamper_class.colors?
end
-
+
def stamper_class
Cutter::Stamper
end
end
@@ -105,9 +117,10 @@
message = messages[lbl] || lbl.to_s
time_passed = time_now - time_initial
print " " * nindent
printf("stamp: %7d ms #{message}\n", time_passed)
end
+ alias_method :stamp!, :stamp
module ClassMethods
def scope label, &block
raise ArgumentError, "Must have hash, was: #{label}" if !label.kind_of? Hash