cutter 0.5.12 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/cutter/stamper.rb +61 -7
- metadata +3 -3
data/lib/cutter/stamper.rb
CHANGED
@@ -1,19 +1,73 @@
|
|
1
|
+
require 'set'
|
2
|
+
|
1
3
|
class Object
|
2
4
|
def time_now
|
3
5
|
Time.now.strftime("%s%L").to_i
|
4
6
|
end
|
5
7
|
|
6
|
-
def stamper
|
7
|
-
|
8
|
-
|
9
|
-
|
8
|
+
def stamper name, &block
|
9
|
+
scope = Stamper[name] || Stamper[:default]
|
10
|
+
msg = 'no msg'
|
11
|
+
if scope
|
12
|
+
message = scope.label.values.first
|
10
13
|
end
|
14
|
+
|
11
15
|
puts("~ #{message}")
|
12
16
|
puts("~ testing: start")
|
13
|
-
|
14
|
-
yield
|
15
|
-
time_passed = time_now -
|
17
|
+
scope.time_initial = time_now
|
18
|
+
yield scope
|
19
|
+
time_passed = time_now - scope.time_initial
|
16
20
|
puts("~ testing: end (#{time_passed}ms)")
|
17
21
|
end
|
22
|
+
end
|
23
|
+
|
24
|
+
class Stamper
|
25
|
+
attr_reader :label
|
26
|
+
attr_accessor :time_initial
|
27
|
+
|
28
|
+
def initialize label
|
29
|
+
@label = label
|
30
|
+
end
|
31
|
+
|
32
|
+
def msg label
|
33
|
+
messages[label.keys.first] = label.values.first
|
34
|
+
end
|
35
|
+
|
36
|
+
alias_method :<<, :msg
|
37
|
+
|
38
|
+
def messages
|
39
|
+
@messages ||= {}
|
40
|
+
end
|
18
41
|
|
42
|
+
def [] key
|
43
|
+
messages[key]
|
44
|
+
end
|
45
|
+
|
46
|
+
def stamp lbl = nil
|
47
|
+
message = messages[lbl] || lbl
|
48
|
+
time_passed = time_now - time_initial
|
49
|
+
printf("~ stamp: %7d ms #{message}\n", time_passed)
|
50
|
+
end
|
51
|
+
|
52
|
+
module ClassMethods
|
53
|
+
def scope label, &block
|
54
|
+
raise ArgumentError, "Must have hash, was: #{label}" if !label.kind_of? Hash
|
55
|
+
raise ArgumentError, "Must have block" if !block
|
56
|
+
stamper = Stamper.new(label)
|
57
|
+
stampers[label.keys.first] = stamper
|
58
|
+
yield stamper
|
59
|
+
stamper
|
60
|
+
end
|
61
|
+
|
62
|
+
def [] key
|
63
|
+
stampers[key]
|
64
|
+
end
|
65
|
+
|
66
|
+
protected
|
67
|
+
|
68
|
+
def stampers
|
69
|
+
@stampers ||= {}
|
70
|
+
end
|
71
|
+
end
|
72
|
+
extend ClassMethods
|
19
73
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: cutter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.
|
5
|
+
version: 0.6.0
|
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-
|
13
|
+
date: 2011-08-07 00:00:00 +03:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -110,7 +110,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
110
110
|
requirements:
|
111
111
|
- - ">="
|
112
112
|
- !ruby/object:Gem::Version
|
113
|
-
hash:
|
113
|
+
hash: 1041591087
|
114
114
|
segments:
|
115
115
|
- 0
|
116
116
|
version: "0"
|