step-track 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/step_track.rb +9 -6
- data/lib/step_track/version.rb +1 -1
- data/test/step_track_test.rb +18 -0
- 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: 1e7fbc29e0c6322fafba55a9cbbdc62edc015b30
|
4
|
+
data.tar.gz: 59a755c0ad211f30927ac47e1ccd4e00d704b279
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d9eaa71b6e0018cefd9631b9df58ae5c90f145db490e15539308d26a56ee9aab7807bd97e420c75296da06f0891a06543186eb1bdfb31776ab739389d03d8240
|
7
|
+
data.tar.gz: 2dcc4bc50959135f4656c455228bba454132abb65c69ddf8a767df24515a9445cdd673e8b1d9b1b1cae482671c123ce03133ecafff0429dd7944f18b8f068e23
|
data/lib/step_track.rb
CHANGED
@@ -5,26 +5,28 @@ module StepTrack
|
|
5
5
|
|
6
6
|
REF = "step_track/%{track}"
|
7
7
|
|
8
|
-
def init(track)
|
8
|
+
def init(track, config={merge_key: :merge, error_key: :error})
|
9
9
|
raise ArgumentError, "callback block required" unless block_given?
|
10
10
|
Thread.current[ref(track)] = {
|
11
11
|
steps: [],
|
12
12
|
callback: Proc.new,
|
13
13
|
time: Time.now
|
14
|
-
}
|
14
|
+
}.merge(config)
|
15
15
|
end
|
16
16
|
|
17
17
|
def push(track, name, payload={})
|
18
18
|
require_init!(track)
|
19
19
|
track_ref = Thread.current[ref(track)]
|
20
|
+
return if track_ref[:steps].last&.[](track_ref[:error_key])
|
21
|
+
merge_step = track_ref[:steps].pop if payload.delete(track_ref[:merge_key])
|
20
22
|
last_step = track_ref[:steps].last
|
21
|
-
track_ref[:steps] << {
|
22
|
-
split: Time.now - (last_step&.[](:time) || track_ref[:time]),
|
23
|
-
duration: Time.now - track_ref[:time],
|
23
|
+
track_ref[:steps] << (merge_step || {}).merge(
|
24
|
+
split: Time.now.to_f - (last_step&.[](:time) || track_ref[:time]).to_f,
|
25
|
+
duration: Time.now.to_f - track_ref[:time].to_f,
|
24
26
|
time: Time.now,
|
25
27
|
caller: caller[0].sub(Dir.pwd + "/", ""),
|
26
28
|
name: name
|
27
|
-
|
29
|
+
).merge(payload)
|
28
30
|
end
|
29
31
|
|
30
32
|
def done(track)
|
@@ -37,6 +39,7 @@ module StepTrack
|
|
37
39
|
result.merge!(steps.last || {})
|
38
40
|
steps.each_with_index do |step, i|
|
39
41
|
name = step[:name]
|
42
|
+
[:split, :duration].each { |k| step[k] = (step[k] * 1000).to_i }
|
40
43
|
result.merge!(step.merge(i: i + 1).
|
41
44
|
map { |k, v| ["step_#{name}_#{k}".to_sym, v] }.to_h)
|
42
45
|
end
|
data/lib/step_track/version.rb
CHANGED
data/test/step_track_test.rb
CHANGED
@@ -51,6 +51,24 @@ describe "StepTrack" do
|
|
51
51
|
expected_keys = [:name, :split, :duration, :time, :caller]
|
52
52
|
assert_equal expected_keys, expected_keys & step.keys
|
53
53
|
end
|
54
|
+
|
55
|
+
it "does nothing when previous step was an error" do
|
56
|
+
StepTrack.push("test", "step", moo: "bar", error: true)
|
57
|
+
data = Thread.current[StepTrack.send(:ref, "test")]
|
58
|
+
assert_equal 1, data[:steps].size
|
59
|
+
StepTrack.push("test", "new")
|
60
|
+
assert_equal 1, data[:steps].size
|
61
|
+
end
|
62
|
+
|
63
|
+
it "merges the new payload into the previous result when requested" do
|
64
|
+
StepTrack.push("test", "step", moo: "bar")
|
65
|
+
StepTrack.push("test", "new", blu: "gnu", merge: true)
|
66
|
+
data = Thread.current[StepTrack.send(:ref, "test")]
|
67
|
+
assert_equal 1, data[:steps].size
|
68
|
+
step = data[:steps].first
|
69
|
+
assert_equal "bar", step[:moo]
|
70
|
+
assert_equal "gnu", step[:blu]
|
71
|
+
end
|
54
72
|
end
|
55
73
|
|
56
74
|
describe ".done" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: step-track
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthias Geier
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-03-
|
11
|
+
date: 2017-03-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|