perforator 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -5
- data/lib/perforator.rb +19 -12
- data/lib/perforator/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2bf643dbc722b7dbc36bec26b4ee133740db9bc0
|
4
|
+
data.tar.gz: cd10ce8280581417049e6c03ecd04097eb2639d6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1fe922088fe59b3be5b31860f1fb70775e82c5dcc61ea755391c41192b315feac1b7e57989c16b3fef5835fe5dda76b00a0468e0e2784daad41c2557e961f631
|
7
|
+
data.tar.gz: ddc6978402ef0cbc2db3871219fd6fea473d302bcbdab58fcfe980a2d2ab41e723c56ac66152d12c8ac5fba6dc87da07ef9e4178f08d6386f16907ec6366423a
|
data/README.md
CHANGED
@@ -79,20 +79,20 @@ my_meter.call do
|
|
79
79
|
end
|
80
80
|
```
|
81
81
|
|
82
|
-
|
82
|
+
Use `log!` method to log additional info
|
83
83
|
```ruby
|
84
84
|
my_meter.call do |meter|
|
85
|
-
meter.
|
85
|
+
meter.log! 'Any start value'
|
86
86
|
# put your code here
|
87
|
-
meter.some_finish '
|
87
|
+
meter.some_finish 'Some finish value'
|
88
88
|
end
|
89
89
|
|
90
90
|
# =======> your label
|
91
|
-
#
|
91
|
+
# Any start value
|
92
92
|
# Start: 2017-06-02 14:24:53 +0300
|
93
93
|
# Finish: 2017-06-02 14:24:54 +0300
|
94
94
|
# Spent: 1.000919
|
95
|
-
#
|
95
|
+
# Some finish value
|
96
96
|
```
|
97
97
|
|
98
98
|
## Development
|
data/lib/perforator.rb
CHANGED
@@ -12,7 +12,7 @@ module Perforator
|
|
12
12
|
def initialize(options = {})
|
13
13
|
@name = options.fetch(:name, nil)
|
14
14
|
@logger = options.fetch(:logger, nil)
|
15
|
-
@
|
15
|
+
@process_puts = options.fetch(:puts, false)
|
16
16
|
@expected_time = options.fetch(:expected_time, nil)
|
17
17
|
@positive_callback = options.fetch(:positive_callback, nil)
|
18
18
|
@negative_callback = options.fetch(:negative_callback, nil)
|
@@ -30,12 +30,21 @@ module Perforator
|
|
30
30
|
finish
|
31
31
|
end
|
32
32
|
|
33
|
-
def
|
34
|
-
|
33
|
+
def log!(content)
|
34
|
+
log_items << content
|
35
35
|
end
|
36
36
|
|
37
37
|
private
|
38
38
|
|
39
|
+
attr_reader :process_puts
|
40
|
+
|
41
|
+
alias_method :process_puts?, :process_puts
|
42
|
+
alias_method :process_logger?, :logger
|
43
|
+
|
44
|
+
def log_items
|
45
|
+
@log_items ||= []
|
46
|
+
end
|
47
|
+
|
39
48
|
def start
|
40
49
|
log! "=======> #{name}"
|
41
50
|
|
@@ -52,6 +61,7 @@ module Perforator
|
|
52
61
|
log! "Spent: #{spent_time}"
|
53
62
|
|
54
63
|
execute_callbacks!
|
64
|
+
release_logs!
|
55
65
|
end
|
56
66
|
|
57
67
|
def execute_callbacks!
|
@@ -61,14 +71,16 @@ module Perforator
|
|
61
71
|
log! "Spent time less than exepcted. Executing: #{positive_callback.inspect}"
|
62
72
|
positive_callback.call
|
63
73
|
elsif spent_time > expected_time && negative_callback
|
64
|
-
log! "Spent time more than exepcted. Executing: #{
|
74
|
+
log! "Spent time more than exepcted. Executing: #{negative_callback.inspect}"
|
65
75
|
negative_callback.call
|
66
76
|
end
|
67
77
|
end
|
68
78
|
|
69
|
-
def
|
70
|
-
|
71
|
-
|
79
|
+
def release_logs!
|
80
|
+
log_items.each do |log_item|
|
81
|
+
puts(log_item) if process_puts?
|
82
|
+
logger.info(log_item) if process_logger?
|
83
|
+
end
|
72
84
|
end
|
73
85
|
|
74
86
|
def callbacks_without_expected_time?
|
@@ -86,10 +98,5 @@ module Perforator
|
|
86
98
|
def expected_time_valid?
|
87
99
|
expected_time.nil? || expected_time.is_a?(Fixnum)
|
88
100
|
end
|
89
|
-
|
90
|
-
# TODO Add possibility to log method_missing keys
|
91
|
-
def method_missing(meth, *args, &blk)
|
92
|
-
log!("#{meth}: #{args[0]}")
|
93
|
-
end
|
94
101
|
end
|
95
102
|
end
|
data/lib/perforator/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: perforator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Volodya Sveredyuk
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-03-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|