Module: Ace::Demo::Atoms::RecordOptionValidator

Defined in:
lib/ace/demo/atoms/record_option_validator.rb

Constant Summary collapse

MP4_UNSUPPORTED_ERROR =
"Unsupported format: mp4. Use gif, or use --backend vhs --format webm for compatibility output."

Class Method Summary collapse

Class Method Details

.normalize_backend(value) ⇒ Object

Raises:

  • (ArgumentError)


12
13
14
15
16
17
18
19
# File 'lib/ace/demo/atoms/record_option_validator.rb', line 12

def normalize_backend(value)
  return nil if value.nil?

  backend = value.to_s.strip.downcase
  return backend if %w[asciinema vhs].include?(backend)

  raise ArgumentError, "Unknown backend '#{backend}'. Valid: asciinema, vhs"
end

.normalize_format(value, supported_formats:, allow_nil: true) ⇒ Object

Raises:

  • (ArgumentError)


21
22
23
24
25
26
27
28
29
# File 'lib/ace/demo/atoms/record_option_validator.rb', line 21

def normalize_format(value, supported_formats:, allow_nil: true)
  return nil if value.nil? && allow_nil

  format = value.to_s.downcase
  raise ArgumentError, MP4_UNSUPPORTED_ERROR if format == "mp4"
  raise ArgumentError, "Unsupported format: #{format}" unless supported_formats.include?(format)

  format
end

.validate_raw_tape_backend!(backend:) ⇒ Object

Raises:

  • (ArgumentError)


37
38
39
40
41
# File 'lib/ace/demo/atoms/record_option_validator.rb', line 37

def validate_raw_tape_backend!(backend:)
  return if backend.nil? || backend == "vhs"

  raise ArgumentError, "Raw .tape recordings support backend 'vhs' only"
end

.validate_yaml_backend_format!(backend:, format:) ⇒ Object

Raises:

  • (ArgumentError)


31
32
33
34
35
# File 'lib/ace/demo/atoms/record_option_validator.rb', line 31

def validate_yaml_backend_format!(backend:, format:)
  return unless format == "webm" && backend != "vhs"

  raise ArgumentError, "Format 'webm' requires --backend vhs when recording YAML tapes"
end