sneakers-queue-migrator 0.1.4 → 0.1.6
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 +15 -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: 5828ad577fd278f6a7aea2c664dc830f16d223718123ff1c777277a1ae3aa1fa
|
4
|
+
data.tar.gz: 33679288215dca825e5f16af92ddf95877e9f0655a2a8e1a73b702ec5f3a3d55
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bfa2182dd468ce08ee611300fb92c1d7f1541bcf2db0e5214b1b1fd47e0a9d36ccec11998800dd9b8a6abdcacb3e247d49a664f173156669747ae8fdf735d203
|
7
|
+
data.tar.gz: cccfd10de6106480a89fbe6ca70351e0ead63e0ca2ec593ad8e3aeecb51ff64a25b0b6896c331a433fb6efeeb0ae73325cd933a23c665281f184ef61439d8246
|
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
@@ -1,3 +1,4 @@
|
|
1
|
+
# rubocop:disable Style/StringConcatenation
|
1
2
|
# frozen_string_literal: true
|
2
3
|
|
3
4
|
require_relative "migrator/version"
|
@@ -13,10 +14,10 @@ module Sneakers
|
|
13
14
|
|
14
15
|
class << self
|
15
16
|
# Main migration entrypoint
|
16
|
-
def migrate!(amqp_url:, amqp_api_url:, subscriber_paths: [], logger: nil,
|
17
|
+
def migrate!(amqp_url:, amqp_api_url:, subscriber_paths: [], logger: nil, load_with_regex: false)
|
17
18
|
logger ||= $stdout
|
18
19
|
# Optionally parse subscribers with regex/static analysis
|
19
|
-
queues = if
|
20
|
+
queues = if load_with_regex
|
20
21
|
parse_queues_from_files(subscriber_paths, logger)
|
21
22
|
else
|
22
23
|
load_files_to_find_queues(subscriber_paths, logger)
|
@@ -102,9 +103,10 @@ module Sneakers
|
|
102
103
|
# Multi-line robust extraction for from_queue calls
|
103
104
|
src_lines = src.lines
|
104
105
|
src_lines.each_with_index do |line, idx|
|
105
|
-
|
106
|
+
# Match from_queue with or without parentheses, any quote style, and allow whitespace
|
107
|
+
next unless line =~ /from_queue\s*(\(|\s)+(['"])([^'"]+)\2\s*,?/
|
106
108
|
|
107
|
-
queue_name = ::Regexp.last_match(
|
109
|
+
queue_name = ::Regexp.last_match(3)
|
108
110
|
# Multi-line argument collection: collect all subsequent lines that are more indented than the from_queue line
|
109
111
|
from_indent = line[/^\s*/].size
|
110
112
|
opts_lines = []
|
@@ -147,6 +149,7 @@ module Sneakers
|
|
147
149
|
queues << q
|
148
150
|
seen[q[:name]] = true
|
149
151
|
end
|
152
|
+
queues
|
150
153
|
end
|
151
154
|
end
|
152
155
|
end
|
@@ -173,6 +176,12 @@ module Sneakers
|
|
173
176
|
|
174
177
|
# Remove comments and excessive whitespace
|
175
178
|
code = str.gsub(/#.*$/, "").gsub(/\n/, " ").gsub(/\s+/, " ")
|
179
|
+
# Convert Ruby %w[ ... ] and %w( ... ) to array syntax for YAML
|
180
|
+
# Also handle %i[ ... ] for symbol arrays
|
181
|
+
code = code.gsub(/%[wi][\[(](.*?)[\])]/) do
|
182
|
+
words = ::Regexp.last_match(1).strip.split(/\s+/)
|
183
|
+
"[" + words.map { |w| "\"#{w}\"" }.join(", ") + "]" # rubocop:disable Style/StringConcatenation
|
184
|
+
end
|
176
185
|
# Convert Ruby hashrockets and symbol keys to YAML style, and handle symbol values and numbers with underscores
|
177
186
|
yaml_str = code
|
178
187
|
.gsub(/:(\w+)\s*=>/, '"\\1":') # :foo =>
|
@@ -417,3 +426,5 @@ module Sneakers
|
|
417
426
|
end
|
418
427
|
end
|
419
428
|
end
|
429
|
+
|
430
|
+
# rubocop:enable Style/StringConcatenation
|