wisco 0.2.3 → 0.2.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/lib/wisco/commands/fixtures.rb +76 -12
- data/lib/wisco/version.rb +1 -1
- 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: 922149837870023d570403cf2ef875643e7201eee6eb425eab6cb98b360448d5
|
|
4
|
+
data.tar.gz: a55d53569027d2628c5dffc31cc078582b1ec1feca64bee7c0087f459e4d8172
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f46fcfb9b5869a7f7bfd1e797752731bb7850bcd81f62209a878703504b578f9f4333bda6ed67db235c29c638e8af095d23f8588c1cd402c490b406a0ef19047
|
|
7
|
+
data.tar.gz: b7a6f96e3899a947d6423bdf6877dc539bbf16c7de569ec39e4c5761092c995fcaebc88f9f4e110aaee200df91eacf681e24fc4470cb56302eb3e0f7a4691f9c
|
|
@@ -47,24 +47,45 @@ module Wisco
|
|
|
47
47
|
elsif section == 'methods'
|
|
48
48
|
process_method(key, connector, fixtures_dir, overwrite: overwrite)
|
|
49
49
|
else
|
|
50
|
+
# ── config_fields pre-check ──────────────────────────────────────
|
|
51
|
+
item = connector[section.to_sym]&.[](key.to_sym)
|
|
52
|
+
raw_cf = item&.[](:config_fields)
|
|
53
|
+
cf_file = File.join(fixtures_dir, 'config_fields.json')
|
|
54
|
+
cf_opt = nil # set to cf_file once the user has filled it in
|
|
55
|
+
|
|
56
|
+
if raw_cf
|
|
57
|
+
if config_fields_ready?(cf_file)
|
|
58
|
+
cf_opt = cf_file
|
|
59
|
+
else
|
|
60
|
+
write_config_fields_template(raw_cf, cf_file)
|
|
61
|
+
warn " Written: #{cf_file}"
|
|
62
|
+
warn " Action required: fill in config_fields.json, then re-run fixtures."
|
|
63
|
+
next
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
# ── input_fields ─────────────────────────────────────────────────
|
|
50
68
|
input_fields_file = File.join(fixtures_dir, 'input_fields.json')
|
|
51
69
|
call_exec(
|
|
52
|
-
path:
|
|
53
|
-
connector:
|
|
54
|
-
connection:
|
|
55
|
-
output:
|
|
56
|
-
|
|
70
|
+
path: "#{section}.#{key}.input_fields",
|
|
71
|
+
connector: connector_full_path,
|
|
72
|
+
connection: connection,
|
|
73
|
+
output: input_fields_file,
|
|
74
|
+
config_fields: cf_opt,
|
|
75
|
+
debug: debug
|
|
57
76
|
)
|
|
58
77
|
|
|
59
78
|
generate_execute_input(input_fields_file, fixtures_dir, overwrite: overwrite, debug: debug)
|
|
60
79
|
|
|
80
|
+
# ── output_fields ────────────────────────────────────────────────
|
|
61
81
|
output_fields_file = File.join(fixtures_dir, 'output_fields.json')
|
|
62
82
|
call_exec(
|
|
63
|
-
path:
|
|
64
|
-
connector:
|
|
65
|
-
connection:
|
|
66
|
-
output:
|
|
67
|
-
|
|
83
|
+
path: "#{section}.#{key}.output_fields",
|
|
84
|
+
connector: connector_full_path,
|
|
85
|
+
connection: connection,
|
|
86
|
+
output: output_fields_file,
|
|
87
|
+
config_fields: cf_opt,
|
|
88
|
+
debug: debug
|
|
68
89
|
)
|
|
69
90
|
end
|
|
70
91
|
end
|
|
@@ -99,6 +120,14 @@ module Wisco
|
|
|
99
120
|
end
|
|
100
121
|
|
|
101
122
|
template = schema_to_template(fields)
|
|
123
|
+
|
|
124
|
+
# Merge config_fields.json if present — its keys are prepended to the template
|
|
125
|
+
cf_file = File.join(fixtures_dir, 'config_fields.json')
|
|
126
|
+
if File.exist?(cf_file)
|
|
127
|
+
cf_template = read_json_without_sentinel(cf_file)
|
|
128
|
+
template = cf_template.merge(template)
|
|
129
|
+
end
|
|
130
|
+
|
|
102
131
|
content = "#{SENTINEL}\n#{JSON.pretty_generate(template)}\n"
|
|
103
132
|
File.write(output_file, content)
|
|
104
133
|
puts " Written: #{output_file}"
|
|
@@ -200,9 +229,44 @@ module Wisco
|
|
|
200
229
|
puts " Written: #{output_file}"
|
|
201
230
|
end
|
|
202
231
|
|
|
203
|
-
def
|
|
232
|
+
def read_json_without_sentinel(path)
|
|
233
|
+
lines = File.readlines(path)
|
|
234
|
+
lines.shift if lines.first&.chomp == SENTINEL
|
|
235
|
+
JSON.parse(lines.join)
|
|
236
|
+
rescue StandardError
|
|
237
|
+
{}
|
|
238
|
+
end
|
|
239
|
+
|
|
240
|
+
def config_fields_ready?(path)
|
|
241
|
+
return false unless File.exist?(path)
|
|
242
|
+
|
|
243
|
+
first_line = begin
|
|
244
|
+
File.open(path, &:readline).chomp
|
|
245
|
+
rescue StandardError
|
|
246
|
+
''
|
|
247
|
+
end
|
|
248
|
+
first_line != SENTINEL
|
|
249
|
+
end
|
|
250
|
+
|
|
251
|
+
def write_config_fields_template(config_fields_array, output_file)
|
|
252
|
+
stringified = stringify_keys_deep(config_fields_array)
|
|
253
|
+
template = schema_to_template(stringified)
|
|
254
|
+
content = "#{SENTINEL}\n#{JSON.pretty_generate(template)}\n"
|
|
255
|
+
File.write(output_file, content)
|
|
256
|
+
end
|
|
257
|
+
|
|
258
|
+
def stringify_keys_deep(obj)
|
|
259
|
+
case obj
|
|
260
|
+
when Hash then obj.transform_keys(&:to_s).transform_values { |v| stringify_keys_deep(v) }
|
|
261
|
+
when Array then obj.map { |e| stringify_keys_deep(e) }
|
|
262
|
+
else obj
|
|
263
|
+
end
|
|
264
|
+
end
|
|
265
|
+
|
|
266
|
+
def call_exec(path:, connector:, connection:, output:, config_fields: nil, debug: false)
|
|
204
267
|
options = { connector: connector, output: output }
|
|
205
|
-
options[:connection]
|
|
268
|
+
options[:connection] = connection if connection
|
|
269
|
+
options[:config_fields] = config_fields if config_fields
|
|
206
270
|
|
|
207
271
|
if debug
|
|
208
272
|
warn "[fixtures] path: #{path}"
|
data/lib/wisco/version.rb
CHANGED