tick 0.1.1 → 0.1.2

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/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- tick (0.1.0)
4
+ tick (0.1.1)
5
5
  rainbow
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -15,10 +15,24 @@ Installation
15
15
 
16
16
  Usge
17
17
  --------
18
+ include Tick
18
19
 
20
+ class Foo
21
+ include Tick
22
+ end
23
+
24
+ Tick your method define method
25
+
19
26
  def foo
20
27
  end
21
28
  tick :foo
29
+
30
+ Sample output without color
31
+
32
+ TICK: method 'foo' in class 'Foo' (0.1 s)
33
+
34
+ Customize message for each method
35
+
22
36
  tick :foo, :message => "benchmark for foo"
23
37
  tick :foo, :message => lambda {|class_name, method_name| " #{class_name}-#{method_name}"}
24
38
 
data/lib/tick.rb CHANGED
@@ -87,10 +87,10 @@ module Tick
87
87
 
88
88
  module ClassMethods
89
89
  def tick(method_name, options = {})
90
- alias_method "#{method_name}_without_tick", method_name
91
- define_method method_name do
92
- result = nil
93
- if Tick.enabled
90
+ if Tick.enabled
91
+ alias_method "#{method_name}_without_tick", method_name
92
+ define_method method_name do
93
+ result = nil
94
94
  sec = Benchmark.realtime { result = self.send("#{method_name}_without_tick") }
95
95
 
96
96
  desc = nil
@@ -102,10 +102,8 @@ module Tick
102
102
 
103
103
  time = Tick.time_message.call(sec)
104
104
  _log_benchmark(desc, time)
105
- else
106
- result = self.send("#{method_name}_without_tick")
105
+ result
107
106
  end
108
- result
109
107
  end
110
108
  end
111
109
  end
data/lib/tick/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Tick
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
data/spec/tick_spec.rb CHANGED
@@ -44,6 +44,7 @@ describe Tick do
44
44
  Tick.enabled.should be false
45
45
  end
46
46
 
47
+
47
48
  it "can set custom desc color" do
48
49
  Tick.desc_color = "#FFC482"
49
50
  Tick.desc_color.should == "#FFC482"
@@ -101,6 +102,17 @@ describe "A class include Tick" do
101
102
  lambda {@klass.send(:tick, :xxx)}.should raise_error
102
103
  end
103
104
 
105
+ it "do not rewrite method if turn of tick" do
106
+ Tick.enabled = false
107
+ @klass.class_eval do
108
+ def default
109
+ sleep 0.5
110
+ end
111
+ end
112
+ @klass.send(:tick, :default)
113
+ @klass.new.should_not respond_to :default_without_tick
114
+ end
115
+
104
116
  describe "tick with options" do
105
117
  before(:each) do
106
118
  @klass.class_eval do
@@ -144,15 +156,6 @@ describe "A class include Tick" do
144
156
  mock(@instance)._log_benchmark(Tick.desc_message.call("TestClass","default"), anything)
145
157
  @instance.default
146
158
  end
147
-
148
- it "should not do benchmark if Tick is turn off" do
149
- dont_allow(Benchmark).realtime(anything)
150
- old_value = Tick.enabled
151
- Tick.enabled = false
152
- @instance.default
153
- Tick.enabled = old_value
154
- end
155
-
156
159
  end
157
160
 
158
161
  describe "#_log_benchmark" do
@@ -168,7 +171,7 @@ describe "A class include Tick" do
168
171
 
169
172
  it "log sec in color" do
170
173
  desc = "TICK: method 'default' in class ''"
171
- time = "(0.1 ms)"
174
+ time = "(0.1 s)"
172
175
  message = ""
173
176
  message << desc
174
177
  message << " "
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: 25
4
+ hash: 31
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 1
10
- version: 0.1.1
9
+ - 2
10
+ version: 0.1.2
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-01 00:00:00 +08:00
18
+ date: 2011-01-03 00:00:00 +08:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency