Module: Insta::ConfigManifest

Defined in:
lib/insta/config_manifest.rb,
sig/insta/config_manifest.rbs

Overview

Bridges configuration from the test process to the standalone CLI.

Insta.configure runs inside the test process (usually from the test helper), which the CLI never loads. Instead of asking users to maintain a separate config file, the test run serializes the CLI-relevant settings next to the snapshots at flush time, and the CLI applies them on startup. Machine-written state, like the pending manifests.

Constant Summary collapse

FILENAME =

Returns:

  • (::String)
".insta-config.json"
SYMBOL_KEYS =

: Array

Returns:

  • (Array[Symbol])
[:diff_display, :diff_color].freeze
RAW_KEYS =

: Array

Returns:

  • (Array[Symbol])
[:diff_width, :snapshot_extension, :heredoc_identifier].freeze

Class Method Summary collapse

Class Method Details

.apply!void

This method returns an undefined value.

: () -> void



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/insta/config_manifest.rb', line 33

def self.apply!
  return unless File.exist?(path)

  manifest = JSON.parse(File.read(path), symbolize_names: true)
  config = Insta.configuration

  SYMBOL_KEYS.each do |key|
    value = manifest[key]
    config.public_send(:"#{key}=", value.to_sym) if value
  end

  RAW_KEYS.each do |key|
    config.public_send(:"#{key}=", manifest[key]) unless manifest[key].nil?
  end
rescue JSON::ParserError
  nil
end

.pathString

: () -> String

Returns:

  • (String)


52
53
54
# File 'lib/insta/config_manifest.rb', line 52

def self.path
  File.join(Insta.configuration.snapshot_path, FILENAME)
end

.write!void

This method returns an undefined value.

: () -> void



21
22
23
24
25
26
27
28
29
30
# File 'lib/insta/config_manifest.rb', line 21

def self.write!
  config = Insta.configuration

  manifest = {} #: Hash[Symbol, untyped]
  SYMBOL_KEYS.each { |key| manifest[key] = config.public_send(key)&.to_s }
  RAW_KEYS.each { |key| manifest[key] = config.public_send(key) }

  FileUtils.mkdir_p(config.snapshot_path)
  File.write(path, JSON.pretty_generate(manifest))
end