rsmp 0.4.0 → 0.4.4

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 05d67026eef7404afe7979c198bcfe97bd63e231400e174988ab14454f23ea09
4
- data.tar.gz: e82717dc287f0eb2e91577cf5e02d752cdf1d1fef6bdac6f4cf3569494d8da3e
3
+ metadata.gz: b82a88e9cd80aeb3bf0bc89b774727155dc8c6418520493c34a852809eb29e94
4
+ data.tar.gz: 16cb2331281e470233ff28fcf6ac1e89124a88628d920f8f3d7e486b0a076b2f
5
5
  SHA512:
6
- metadata.gz: 0d971e86ebd1ef25ff52cc4babd23567b2b5e870cc70f7edfc18ce7925a850fd94dfa851e70c16a43d4df1ef174045999ad41c0fd5ad2ed7c074ae022282e441
7
- data.tar.gz: 5f991d2aee4af7ac5a30b133ecfa8e1505b005fbc8e7092551f0d28bd4d26cee36fb645aa188e8a9664c0a7d5c991c78a2059445c82e1ec697ff14a8df3d2cdf
6
+ metadata.gz: 47d08d2fab1e0dd76dc5e988b3ee4e56a3110258402ffc9d1d8213ca7cbd889e94d08119100b785dfc5803dfd5f0618ac25c2597e1499cebd7fbd2db500614d5
7
+ data.tar.gz: 321f695677507a66fa03a81fc2bdc87350df51278e53e95bb6f75e5eeea180ea3e1503f0ee072aea425970d32e7a814a8a683cd33abdf7d832cd8c83e216ff97
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rsmp (0.4.0)
4
+ rsmp (0.4.3)
5
5
  async (~> 1.29.1)
6
6
  async-io (~> 1.32.1)
7
7
  colorize (~> 0.8.1)
@@ -1,6 +1,6 @@
1
1
  module RSMP
2
2
 
3
- # Collects ingoing and/or outgoing messages.
3
+ # Collects ingoing and/or outgoing messages from a notifier.
4
4
  # Can filter by message type and wakes up the client once the desired number of messages has been collected.
5
5
  class Collector < Listener
6
6
  attr_reader :condition, :messages, :done
@@ -17,22 +17,29 @@ module RSMP
17
17
  reset
18
18
  end
19
19
 
20
+ # Inspect formatter that shows the message we have collected
20
21
  def inspect
21
22
  "#<#{self.class.name}:#{self.object_id}, #{inspector(:@messages)}>"
22
23
  end
23
24
 
25
+ # Want ingoing messages?
24
26
  def ingoing?
25
27
  @ingoing == true
26
28
  end
27
29
 
30
+ # Want outgoing messages?
28
31
  def outgoing?
29
32
  @outgoing == true
30
33
  end
31
34
 
35
+ # Block until all messages have been collected
32
36
  def wait
33
37
  @condition.wait
34
38
  end
35
39
 
40
+ # Collect message
41
+ # Will block until all messages have been collected,
42
+ # or we time out
36
43
  def collect task, options={}, &block
37
44
  @options.merge! options
38
45
  @block = block
@@ -46,9 +53,9 @@ module RSMP
46
53
  return @error if @error
47
54
  self
48
55
  rescue Async::TimeoutError
49
- str = "Did not receive #{@title}"
56
+ str = "#{@title.capitalize} collection"
50
57
  str << " in response to #{options[:m_id]}" if options[:m_id]
51
- str << " within #{@options[:timeout]}s"
58
+ str << " didn't complete within #{@options[:timeout]}s"
52
59
  raise RSMP::TimeoutError.new str
53
60
  end
54
61
 
@@ -35,10 +35,11 @@ module RSMP
35
35
  class Matcher < Collector
36
36
  attr_reader :queries
37
37
 
38
- # Initialize with a list a wanted statuses
38
+ # Initialize with a list of wanted statuses
39
39
  def initialize proxy, want, options={}
40
40
  super proxy, options.merge( ingoing: true, outgoing: false)
41
- @queries = want.map { |wanted_item| build_query wanted_item }
41
+ @queries = want.map { |item| build_query item }
42
+ @want = want
42
43
  end
43
44
 
44
45
  # Build a query object.
@@ -51,10 +52,15 @@ module RSMP
51
52
  def query_result want
52
53
  query = @queries.find { |q| q.want == want}
53
54
  raise unless query
54
- query.item
55
+ query.got
55
56
  end
56
57
 
57
- # get the first message. Useful when you only collected one mesage
58
+ # Get an array of the last item received for each query
59
+ def reached
60
+ @queries.map { |query| query.got }.compact
61
+ end
62
+
63
+ # get the first message. Useful when you only collect one mesage
58
64
  def message
59
65
  @queries.first.message
60
66
  end
@@ -64,11 +70,6 @@ module RSMP
64
70
  @queries.map { |query| query.message }.uniq
65
71
  end
66
72
 
67
- # Get items from results
68
- def items
69
- @queries.map { |query| query.item }.uniq
70
- end
71
-
72
73
  # Are there queries left to match?
73
74
  def done?
74
75
  @queries.all? { |query| query.done? }
@@ -77,24 +78,30 @@ module RSMP
77
78
  # Get a simplified hash of queries, with values set to either true or false,
78
79
  # indicating which queries have been matched.
79
80
  def status
80
- @queries.map { |query| [query.query,query.done?] }.to_h
81
+ @queries.map { |query| [query.want, query.done?] }.to_h
81
82
  end
82
83
 
83
- # Get a simply array of bools, showing which queries ahve been matched.
84
+ # Get a simply array of bools, showing which queries have been matched.
84
85
  def summary
85
86
  @queries.map { |query| query.done? }
86
87
  end
87
88
 
88
89
  # Check if a messages matches our criteria.
89
- # We iterate through each of the status items or return values in the message
90
- # Breaks as soon as where done matching all queries
90
+ # Match each query against each item in the message
91
91
  def check_match message
92
92
  return unless match?(message)
93
93
  @queries.each do |query| # look through queries
94
- get_items(message).each do |item| # look through status items in message
95
- break if query.check_match(item,message) != nil #check_item_match message, query, item
94
+ get_items(message).each do |item| # look through items in message
95
+ matched = query.check_match(item,message)
96
+ if matched != nil
97
+ type = {true=>'match',false=>'mismatch'}[matched]
98
+ @proxy.log "#{@title.capitalize} #{message.m_id_short} collect #{type} #{query.want}, item #{item}", level: :debug
99
+ break
100
+ end
96
101
  end
97
102
  end
103
+ @proxy.log "#{@title.capitalize} collect reached #{summary}", level: :debug
98
104
  end
105
+
99
106
  end
100
107
  end
@@ -23,9 +23,9 @@ module RSMP
23
23
  return nil if @want['n'] && @want['n'] != item['n']
24
24
  return false if @want['q'] && @want['q'] != item['q']
25
25
  if @want['s'].is_a? Regexp
26
- return false if @want['s'] && item['s'] !~ @want['s']
27
- else
28
- return false if @want['s'] && item['s'] != @want['s']
26
+ return false if item['s'] !~ @want['s']
27
+ elsif @want['s']
28
+ return false if item['s'] != @want['s']
29
29
  end
30
30
  true
31
31
  end
@@ -2,43 +2,33 @@ module RSMP
2
2
 
3
3
  # Class that matches a single status or command item
4
4
  class Query
5
- attr_reader :want, :item, :message
5
+ attr_reader :want, :got, :message
6
6
 
7
7
  def initialize want
8
8
  @want = want
9
- @item = nil
9
+ @got = nil
10
10
  @message = nil
11
11
  @done = false
12
12
  end
13
13
 
14
+ # Are we done, i.e. did the last checked item match?
14
15
  def done?
15
16
  @done
16
17
  end
17
18
 
19
+ # Check an item and set @done to true if it matches
20
+ # Store the item and corresponding message if there's a positive or negative match
18
21
  def check_match item, message
19
22
  matched = match? item
20
- if matched == true
21
- keep message, item
22
- true
23
- elsif matched == false
24
- forget
25
- true
23
+ if matched != nil
24
+ @message = message
25
+ @got = item
26
+ @done = matched
26
27
  end
28
+ matched
27
29
  end
28
30
 
29
31
  def match? item
30
32
  end
31
-
32
- # Mark a query as matched and store item and message
33
- def keep message, item
34
- @message = message
35
- @item = item
36
- @done = true
37
- end
38
-
39
- # Mark a query as not matched
40
- def forget
41
- @done = false
42
- end
43
33
  end
44
34
  end
data/lib/rsmp/tlc.rb CHANGED
@@ -293,7 +293,6 @@ module RSMP
293
293
  def handle_s0002 status_code, status_name=nil
294
294
  case status_name
295
295
  when 'detectorlogicstatus'
296
- RSMP::Tlc.make_status @detector_logics.each { |dl| p dl.value }
297
296
  RSMP::Tlc.make_status @detector_logics.map { |dl| dl.value ? '1' : '0' }.join
298
297
  end
299
298
  end
data/lib/rsmp/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module RSMP
2
- VERSION = "0.4.0"
2
+ VERSION = "0.4.4"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rsmp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Emil Tin
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-10-27 00:00:00.000000000 Z
11
+ date: 2021-10-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: async