cutter 0.8.0 → 0.8.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/cutter/stamper.rb +94 -78
  2. metadata +2 -2
@@ -12,14 +12,10 @@ class Object
12
12
  log_coloured sp, msg, color(:time)
13
13
  end
14
14
 
15
- def color type
16
- Stamper.colors_config[type] if Stamper.colors?
17
- end
18
-
19
- return if Stamper.off?
20
- scope = Stamper[name] || Stamper[:default]
21
- scope.indent = Stamper.last ? Stamper.last.indent + 1 : 0
22
- Stamper.push scope
15
+ return if stamper_class.off?
16
+ scope = stamper_class[name] || stamper_class[:default]
17
+ scope.indent = stamper_class.last ? stamper_class.last.indent + 1 : 0
18
+ stamper_class.push scope
23
19
 
24
20
  msg = 'no msg'
25
21
  if scope
@@ -31,109 +27,129 @@ class Object
31
27
  scope.time_initial = time_now
32
28
  yield scope
33
29
  scope.indent -= 1 if scope.indent > 0
34
- Stamper.pop
30
+ stamper_class.pop
35
31
  time_passed = time_now - scope.time_initial
36
32
  log_coloured spaces, "~ END " << "#{message}"
37
33
  log_time spaces, "[#{time_passed}ms]"
38
34
  line spaces
39
35
  end
40
- end
41
-
42
- class Stamper
43
- attr_reader :label
44
- attr_accessor :time_initial
45
- attr_writer :indent
46
-
47
- include Cutter::ColoredOutputs
48
-
49
- def initialize label
50
- @label = label
51
- @indent = 0
52
- end
53
36
 
54
- def self.turn state = :on
55
- @state = state
56
- end
37
+ private
57
38
 
58
- def self.on?
59
- @state ||= :on
60
- @state == :on
39
+ def color type
40
+ stamper_class.colors_config[type] if stamper_class.colors?
61
41
  end
62
-
63
- def self.off?
64
- !on?
42
+
43
+ def stamper_class
44
+ Cutter::Stamper
65
45
  end
46
+ end
66
47
 
67
- def indent
68
- @indent ||= 0
69
- end
48
+ module Cutter
49
+ class Stamper
50
+ attr_reader :label
51
+ attr_accessor :time_initial
52
+ attr_writer :indent
70
53
 
71
- def nindent
72
- @indent +1
73
- end
54
+ include Cutter::ColoredOutputs
74
55
 
75
- def msg label
76
- messages[label.keys.first] = label.values.first
77
- end
56
+ def initialize label
57
+ @label = label
58
+ @indent = 0
59
+ end
78
60
 
79
- alias_method :<<, :msg
61
+ def self.turn state = :on
62
+ @@state = state
63
+ end
80
64
 
81
- def messages
82
- @messages ||= {}
83
- end
65
+ def self.quiet!
66
+ self.turn :off
67
+ end
84
68
 
85
- def [] key
86
- messages[key]
87
- end
69
+ def self.loud!
70
+ self.turn :on
71
+ end
88
72
 
89
- def stamp lbl = nil
90
- return if Stamper.off?
91
- message = messages[lbl] || lbl.to_s.humanize
92
- time_passed = time_now - time_initial
93
- print " " * nindent
94
- printf("~ stamp: %7d ms #{message}\n", time_passed)
95
- end
73
+ def self.on?
74
+ @@state ||= :on
75
+ @@state == :on
76
+ end
96
77
 
97
- module ClassMethods
78
+ def self.off?
79
+ !on?
80
+ end
98
81
 
99
- def scope label, &block
100
- raise ArgumentError, "Must have hash, was: #{label}" if !label.kind_of? Hash
101
- raise ArgumentError, "Must have block" if !block
102
- stamper = Stamper.new(label)
103
- stampers[label.keys.first] = stamper
104
- yield stamper
105
- stamper_stack.pop
106
- stamper
82
+ def indent
83
+ @indent ||= 0
107
84
  end
108
85
 
109
- def last
110
- stamper_stack.last
86
+ def nindent
87
+ @indent +1
111
88
  end
112
89
 
113
- def push stamper
114
- stamper_stack.push stamper
90
+ def msg label
91
+ messages[label.keys.first] = label.values.first
115
92
  end
116
93
 
117
- def pop
118
- stamper_stack.pop
94
+ alias_method :<<, :msg
95
+
96
+ def messages
97
+ @messages ||= {}
119
98
  end
120
99
 
121
100
  def [] key
122
- stampers[key]
101
+ messages[key]
123
102
  end
124
103
 
125
- protected
126
-
127
- def stamper_stack
128
- @stamper_stack ||= []
104
+ def stamp lbl = nil
105
+ return if Stamper.off?
106
+ message = messages[lbl] || lbl.to_s.humanize
107
+ time_passed = time_now - time_initial
108
+ print " " * nindent
109
+ printf("~ stamp: %7d ms #{message}\n", time_passed)
129
110
  end
130
111
 
131
- def stampers
132
- @stampers ||= {}
112
+ module ClassMethods
113
+
114
+ def scope label, &block
115
+ raise ArgumentError, "Must have hash, was: #{label}" if !label.kind_of? Hash
116
+ raise ArgumentError, "Must have block" if !block
117
+ stamper = Stamper.new(label)
118
+ stampers[label.keys.first] = stamper
119
+ yield stamper
120
+ stamper_stack.pop
121
+ stamper
122
+ end
123
+
124
+ def last
125
+ stamper_stack.last
126
+ end
127
+
128
+ def push stamper
129
+ stamper_stack.push stamper
130
+ end
131
+
132
+ def pop
133
+ stamper_stack.pop
134
+ end
135
+
136
+ def [] key
137
+ stampers[key]
138
+ end
139
+
140
+ protected
141
+
142
+ def stamper_stack
143
+ @stamper_stack ||= []
144
+ end
145
+
146
+ def stampers
147
+ @stampers ||= {}
148
+ end
133
149
  end
150
+ extend ClassMethods
134
151
  end
135
- extend ClassMethods
136
152
  end
137
153
 
138
- Stamper.scope :default => nil do |default|
154
+ Cutter::Stamper.scope :default => nil do |default|
139
155
  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.0
5
+ version: 0.8.1
6
6
  platform: ruby
7
7
  authors:
8
8
  - stanislaw
@@ -100,7 +100,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
100
100
  requirements:
101
101
  - - ">="
102
102
  - !ruby/object:Gem::Version
103
- hash: 800208499
103
+ hash: -666484749
104
104
  segments:
105
105
  - 0
106
106
  version: "0"