sneakers-queue-migrator 0.1.4 → 0.1.5
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 +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +2 -2
- data/lib/sneakers/migrator/version.rb +1 -1
- data/lib/sneakers/migrator.rb +11 -4
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 07b21432931960e830cbb956ab0e53406657147d9674f495ef74237f114e6fc3
|
4
|
+
data.tar.gz: aa60dd0d5714f56410240567c0a63da1fa937eefd6d3ad706bdb8a6b35cd2bdc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: af7f10c370532ceb2f76d908bd86fc5d5743cb1c6b491de59ef2eb3fd6749b19ccd6da1a44368c398f51281ce6440e81abd3aa6fb5d3a2f7110de84d5507b99a
|
7
|
+
data.tar.gz: 772f61353f22feea63646cebe38eaf2c6f0c2864a0041b74f54a6eba88cbf01a2c569780b3ac379899c61b6d8137253187e1376f02bfeeac53bf0a707f9241af
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -36,14 +36,14 @@ Sneakers::Migrator.migrate!(
|
|
36
36
|
amqp_url: 'amqp://user:password@rabbitmq:5672/',
|
37
37
|
amqp_api_url: 'http://user:password@rabbitmq:15672',
|
38
38
|
subscriber_paths: ['app/workers'],
|
39
|
-
|
39
|
+
load_with_regex: false
|
40
40
|
)
|
41
41
|
```
|
42
42
|
|
43
43
|
`amqp_url` - regular bunny connection string
|
44
44
|
`amqp_api_url` - url WITH PORT for the management interface
|
45
45
|
`subscriber_paths` - array of folders to scan for subscribers
|
46
|
-
`
|
46
|
+
`load_with_regex` - `false` requires the files and reflects the arguments, `true` parses the from_queue block with regex
|
47
47
|
|
48
48
|
## Development
|
49
49
|
|
data/lib/sneakers/migrator.rb
CHANGED
@@ -13,10 +13,10 @@ module Sneakers
|
|
13
13
|
|
14
14
|
class << self
|
15
15
|
# Main migration entrypoint
|
16
|
-
def migrate!(amqp_url:, amqp_api_url:, subscriber_paths: [], logger: nil,
|
16
|
+
def migrate!(amqp_url:, amqp_api_url:, subscriber_paths: [], logger: nil, load_with_regex: false)
|
17
17
|
logger ||= $stdout
|
18
18
|
# Optionally parse subscribers with regex/static analysis
|
19
|
-
queues = if
|
19
|
+
queues = if load_with_regex
|
20
20
|
parse_queues_from_files(subscriber_paths, logger)
|
21
21
|
else
|
22
22
|
load_files_to_find_queues(subscriber_paths, logger)
|
@@ -102,9 +102,10 @@ module Sneakers
|
|
102
102
|
# Multi-line robust extraction for from_queue calls
|
103
103
|
src_lines = src.lines
|
104
104
|
src_lines.each_with_index do |line, idx|
|
105
|
-
|
105
|
+
# Match from_queue with or without parentheses, any quote style, and allow whitespace
|
106
|
+
next unless line =~ /from_queue\s*(\(|\s)+(['"])([^'"]+)\2\s*,?/
|
106
107
|
|
107
|
-
queue_name = ::Regexp.last_match(
|
108
|
+
queue_name = ::Regexp.last_match(3)
|
108
109
|
# Multi-line argument collection: collect all subsequent lines that are more indented than the from_queue line
|
109
110
|
from_indent = line[/^\s*/].size
|
110
111
|
opts_lines = []
|
@@ -147,6 +148,7 @@ module Sneakers
|
|
147
148
|
queues << q
|
148
149
|
seen[q[:name]] = true
|
149
150
|
end
|
151
|
+
queues
|
150
152
|
end
|
151
153
|
end
|
152
154
|
end
|
@@ -173,6 +175,11 @@ module Sneakers
|
|
173
175
|
|
174
176
|
# Remove comments and excessive whitespace
|
175
177
|
code = str.gsub(/#.*$/, "").gsub(/\n/, " ").gsub(/\s+/, " ")
|
178
|
+
# Convert Ruby %w[ ... ] and %w( ... ) to array syntax for YAML
|
179
|
+
code = code.gsub(/%w[\[(](.*?)[\])]/) do
|
180
|
+
words = ::Regexp.last_match(1).strip.split(/\s+/)
|
181
|
+
"[" + words.map { |w| "\"#{w}\"" }.join(", ") + "]" # rubocop:disable Style/StringConcatenation
|
182
|
+
end
|
176
183
|
# Convert Ruby hashrockets and symbol keys to YAML style, and handle symbol values and numbers with underscores
|
177
184
|
yaml_str = code
|
178
185
|
.gsub(/:(\w+)\s*=>/, '"\\1":') # :foo =>
|