Module: Ace::Assign::Molecules::PresetInferrer

Defined in:
lib/ace/assign/molecules/preset_inferrer.rb

Overview

Infers assignment preset from archived source config.

Constant Summary collapse

DEFAULT_PRESET =
"work-on-task"

Class Method Summary collapse

Class Method Details

.infer_from_assignment(assignment) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/ace/assign/molecules/preset_inferrer.rb', line 12

def self.infer_from_assignment(assignment)
  return DEFAULT_PRESET unless assignment

  source_path = assignment.source_config.to_s
  return DEFAULT_PRESET if source_path.empty? || !File.exist?(source_path)

  data = YAML.safe_load_file(source_path, aliases: true)
  return DEFAULT_PRESET unless data.is_a?(Hash)

  session_name = data.dig("session", "name").to_s.strip
  return session_name unless session_name.empty?

  DEFAULT_PRESET
rescue Psych::SyntaxError, Errno::ENOENT
  DEFAULT_PRESET
end