tick 0.1.2 → 0.1.3
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.
- data/lib/tick.rb +14 -10
- data/lib/tick/version.rb +1 -1
- data/spec/tick_spec.rb +9 -0
- metadata +4 -4
data/lib/tick.rb
CHANGED
@@ -91,17 +91,21 @@ module Tick
|
|
91
91
|
alias_method "#{method_name}_without_tick", method_name
|
92
92
|
define_method method_name do
|
93
93
|
result = nil
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
94
|
+
if Tick.enabled #user may turn off tick at runtime
|
95
|
+
sec = Benchmark.realtime { result = self.send("#{method_name}_without_tick") }
|
96
|
+
desc = nil
|
97
|
+
if options[:message].kind_of?(Proc)
|
98
|
+
desc = options[:message].call(self.class.name, method_name)
|
99
|
+
else
|
100
|
+
desc = options[:message] || Tick.desc_message.call(self.class.name, method_name)
|
101
|
+
end
|
102
|
+
|
103
|
+
time = Tick.time_message.call(sec)
|
104
|
+
_log_benchmark(desc, time)
|
105
|
+
else
|
106
|
+
result = self.send("#{method_name}_without_tick")
|
101
107
|
end
|
102
|
-
|
103
|
-
time = Tick.time_message.call(sec)
|
104
|
-
_log_benchmark(desc, time)
|
108
|
+
|
105
109
|
result
|
106
110
|
end
|
107
111
|
end
|
data/lib/tick/version.rb
CHANGED
data/spec/tick_spec.rb
CHANGED
@@ -156,6 +156,15 @@ describe "A class include Tick" do
|
|
156
156
|
mock(@instance)._log_benchmark(Tick.desc_message.call("TestClass","default"), anything)
|
157
157
|
@instance.default
|
158
158
|
end
|
159
|
+
|
160
|
+
it "should not do benchmark if Tick is turn off at runtime" do
|
161
|
+
dont_allow(Benchmark).realtime(anything)
|
162
|
+
old_value = Tick.enabled
|
163
|
+
Tick.enabled = false
|
164
|
+
@instance.default
|
165
|
+
Tick.enabled = old_value
|
166
|
+
end
|
167
|
+
|
159
168
|
end
|
160
169
|
|
161
170
|
describe "#_log_benchmark" do
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tick
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 29
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 3
|
10
|
+
version: 0.1.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- allenwei
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-01-
|
18
|
+
date: 2011-01-04 00:00:00 +08:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|