evt-telemetry 0.3.0.2 → 0.3.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/telemetry/sink.rb +45 -7
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 26b3206c47d50d29e01fe0e76189c645dd383533
4
- data.tar.gz: 5b71c41d0fefbbf34ac353a7a40a070d8d5da63b
3
+ metadata.gz: 4232dd7cc989788094d9f1fdc6e26e1be6dbe4d3
4
+ data.tar.gz: a903d2a73c86cca54109dad9cc4659f79a3ffa02
5
5
  SHA512:
6
- metadata.gz: 74fcaedcd52f1be33bb6f8e43e40a0bca265f8e2d412af948a37d192e041043ad83e91f71b853c568230e381bcac509c15384e0933a260cf8caacb1633ccca19
7
- data.tar.gz: d6775bb7db74ef5094f5d66c830c8e6f7acb122a0da2c8b3805fc15b47bd871d1c4b98625e828957a72bdecf159a547de67b6a96ec891fc35b532425b88c2737
6
+ metadata.gz: 66070195dee9f9a98ce3159d38ced027bbc63af8a87c0479c89c504e0943024e3e9181c37475572bd02d34469f455528fa798dd413ce4e6233e1c5c65569518e
7
+ data.tar.gz: bdc41431c61a77ccb3fbdc888d9c8a181593efdd28e5c606e2ca87b8690ff6c7c6b2a47712fda8e452ddf312fd7e7872440ba67e274368c339e240ca0e9aa900
@@ -37,6 +37,17 @@ class Telemetry
37
37
  return subset.any? &blk
38
38
  end
39
39
  end
40
+
41
+ detect_once_method_name = "recorded_#{signal}_once?"
42
+ send(:define_method, detect_once_method_name) do |&blk|
43
+ subset = send(subset_method_name)
44
+
45
+ if blk.nil?
46
+ return subset.count == 1
47
+ else
48
+ return subset.one? &blk
49
+ end
50
+ end
40
51
  end
41
52
  alias :record :record_macro
42
53
  end
@@ -52,6 +63,8 @@ class Telemetry
52
63
 
53
64
  Record = Struct.new :signal, :time, :data
54
65
 
66
+ Error = Class.new(RuntimeError)
67
+
55
68
  def records
56
69
  @records ||= []
57
70
  end
@@ -72,6 +85,17 @@ class Telemetry
72
85
  record
73
86
  end
74
87
 
88
+ def record(signal, time, data=nil, force: nil)
89
+ force ||= false
90
+
91
+ record = nil
92
+ if force || record?(signal)
93
+ record = Record.new signal, time, data
94
+ records << record
95
+ end
96
+ record
97
+ end
98
+
75
99
  def recorded?(&blk)
76
100
  if blk.nil?
77
101
  return !records.empty?
@@ -80,15 +104,29 @@ class Telemetry
80
104
  end
81
105
  end
82
106
 
83
- def record(signal, time, data=nil, force: nil)
84
- force ||= false
107
+ def recorded_once?(&blk)
108
+ if blk.nil?
109
+ return records.count == 1
110
+ else
111
+ return records.one? &blk
112
+ end
113
+ end
85
114
 
86
- record = nil
87
- if force || record?(signal)
88
- record = Record.new signal, time, data
89
- records << record
115
+ def one_record(&blk)
116
+ records = self.records
117
+
118
+ unless blk.nil?
119
+ records = records.select(&blk)
120
+ end
121
+
122
+ case records.count
123
+ when 0
124
+ return nil
125
+ when 1
126
+ return records[0]
127
+ else
128
+ raise Error, "More than one matching record was recorded"
90
129
  end
91
- record
92
130
  end
93
131
  end
94
132
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: evt-telemetry
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0.2
4
+ version: 0.3.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - The Eventide Project
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-06-01 00:00:00.000000000 Z
11
+ date: 2017-06-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: evt-dependency