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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 51be86dee6508b94fdfb404c37a7550de6f73497df168fc78b220021bbfdb5bd
4
- data.tar.gz: 015f92b59cee11340d40c075be7f8cd73f08efa2d18442ec37bc41def1aa1273
3
+ metadata.gz: 922149837870023d570403cf2ef875643e7201eee6eb425eab6cb98b360448d5
4
+ data.tar.gz: a55d53569027d2628c5dffc31cc078582b1ec1feca64bee7c0087f459e4d8172
5
5
  SHA512:
6
- metadata.gz: 5a81968e4a3aaf8164fbe849c049a525f6bb9853cfb39e1fb5c9d4f090ca9f98669aa7151b9ab36efba1ec8875869df10401e2524a405bb12e590eb5e39bc869
7
- data.tar.gz: b07cc5ea7da1bc2f34f12d342a63822250f818a0372dd70a4b6d2172badd2dad31f99cdf63a787841a97cee3302b75625d40fd1c2bfdae54152d7197444f6d91
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: "#{section}.#{key}.input_fields",
53
- connector: connector_full_path,
54
- connection: connection,
55
- output: input_fields_file,
56
- debug: debug
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: "#{section}.#{key}.output_fields",
64
- connector: connector_full_path,
65
- connection: connection,
66
- output: output_fields_file,
67
- debug: debug
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 call_exec(path:, connector:, connection:, output:, debug: false)
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] = connection if 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
@@ -1,3 +1,3 @@
1
1
  module Wisco
2
- VERSION = '0.2.3'
2
+ VERSION = '0.2.6'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wisco
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - mbillington