rsmp 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/rsmp/collect/collector.rb +10 -3
- data/lib/rsmp/collect/matcher.rb +20 -11
- data/lib/rsmp/collect/message_queries.rb +3 -3
- data/lib/rsmp/collect/query.rb +9 -21
- data/lib/rsmp/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b37598da5f9d49f45c771f6cefeae320304caeaa4c9e8c50ba005442554c88f4
|
4
|
+
data.tar.gz: 29f72fa255248e3c3bb27946877714f262235f252da551d6e4941efbc5b12547
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d1dd3458a8a619ee06bffd194f93aa16b7b00874d0c76ff52c00b23f5081ea6dde7dbe3e8eb5c5736b6e05938894a6278a1a870a5ea0cb318c962ff2663cddc2
|
7
|
+
data.tar.gz: 70f633dc8a56995df2b1439467664fc00c861208d80fa2da14fc473413aa3d6186a9fd5bc0a727632757a6fececbb5fd5ed6456cdfcb74623db97eeb321637ab
|
data/Gemfile.lock
CHANGED
@@ -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 = "
|
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
|
|
data/lib/rsmp/collect/matcher.rb
CHANGED
@@ -35,10 +35,11 @@ module RSMP
|
|
35
35
|
class Matcher < Collector
|
36
36
|
attr_reader :queries
|
37
37
|
|
38
|
-
# Initialize with a list
|
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 { |
|
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.
|
55
|
+
query.got
|
55
56
|
end
|
56
57
|
|
57
|
-
#
|
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.
|
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
|
-
|
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
|
27
|
-
|
28
|
-
return false if
|
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
|
data/lib/rsmp/collect/query.rb
CHANGED
@@ -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, :
|
5
|
+
attr_reader :want, :got, :message
|
6
6
|
|
7
7
|
def initialize want
|
8
8
|
@want = want
|
9
|
-
@
|
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
|
21
|
-
|
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
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.
|
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-
|
11
|
+
date: 2021-10-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: async
|