rsmp 0.4.0 → 0.4.1

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: b37598da5f9d49f45c771f6cefeae320304caeaa4c9e8c50ba005442554c88f4
4
+ data.tar.gz: 29f72fa255248e3c3bb27946877714f262235f252da551d6e4941efbc5b12547
5
5
  SHA512:
6
- metadata.gz: 0d971e86ebd1ef25ff52cc4babd23567b2b5e870cc70f7edfc18ce7925a850fd94dfa851e70c16a43d4df1ef174045999ad41c0fd5ad2ed7c074ae022282e441
7
- data.tar.gz: 5f991d2aee4af7ac5a30b133ecfa8e1505b005fbc8e7092551f0d28bd4d26cee36fb645aa188e8a9664c0a7d5c991c78a2059445c82e1ec697ff14a8df3d2cdf
6
+ metadata.gz: d1dd3458a8a619ee06bffd194f93aa16b7b00874d0c76ff52c00b23f5081ea6dde7dbe3e8eb5c5736b6e05938894a6278a1a870a5ea0cb318c962ff2663cddc2
7
+ data.tar.gz: 70f633dc8a56995df2b1439467664fc00c861208d80fa2da14fc473413aa3d6186a9fd5bc0a727632757a6fececbb5fd5ed6456cdfcb74623db97eeb321637ab
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.1)
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,7 +78,7 @@ 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
84
  # Get a simply array of bools, showing which queries ahve been matched.
@@ -92,9 +93,17 @@ module RSMP
92
93
  return unless match?(message)
93
94
  @queries.each do |query| # look through queries
94
95
  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
96
+ matched = query.check_match(item,message)
97
+ if matched != nil
98
+ type = {true=>'positive',false=>'negative'}[matched]
99
+ @proxy.log "Query #{query.want} has #{type} match with item #{item}, reached #{summary}", message: message, level: :info
100
+ break matched
101
+ end
96
102
  end
97
103
  end
104
+ # @proxy.log "match", level: :info
105
+ nil
98
106
  end
107
+
99
108
  end
100
109
  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,31 @@ 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
+ # Always store the item and corresponding message.
18
21
  def check_match item, message
22
+ @message = message
23
+ @got = item
19
24
  matched = match? item
20
- if matched == true
21
- keep message, item
22
- true
23
- elsif matched == false
24
- forget
25
- true
26
- end
25
+ @done = matched if matched != nil
26
+ matched
27
27
  end
28
28
 
29
29
  def match? item
30
30
  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
31
  end
44
32
  end
data/lib/rsmp/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module RSMP
2
- VERSION = "0.4.0"
2
+ VERSION = "0.4.1"
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.1
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-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: async