Class: Ace::Idea::Molecules::IdeaResolver

Inherits:
Object
  • Object
show all
Defined in:
lib/ace/idea/molecules/idea_resolver.rb

Overview

Wraps ShortcutResolver for raw idea IDs (no .t. type marker). Resolves 3-char suffix shortcuts, full 6-char IDs. Explicitly detects and warns on ambiguity collisions.

Instance Method Summary collapse

Constructor Details

#initialize(root_dir) ⇒ IdeaResolver

Returns a new instance of IdeaResolver.

Parameters:

  • root_dir (String)

    Root directory containing ideas



14
15
16
17
# File 'lib/ace/idea/molecules/idea_resolver.rb', line 14

def initialize(root_dir)
  @root_dir = root_dir
  @scanner = IdeaScanner.new(root_dir)
end

Instance Method Details

#resolve(ref, warn_on_ambiguity: true) ⇒ ScanResult?

Resolve a reference to a scan result

Parameters:

  • ref (String)

    Full ID (6 chars) or suffix shortcut (3 chars)

  • warn_on_ambiguity (Boolean) (defaults to: true)

    Whether to print warning on ambiguity

Returns:

  • (ScanResult, nil)

    Resolved result or nil



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/ace/idea/molecules/idea_resolver.rb', line 23

def resolve(ref, warn_on_ambiguity: true)
  scan_results = @scanner.scan
  resolver = Ace::Support::Items::Molecules::ShortcutResolver.new(scan_results)

  on_ambiguity = if warn_on_ambiguity
    ->(matches) {
      ids = matches.map(&:id).join(", ")
      warn "Warning: Ambiguous shortcut '#{ref}' matches #{matches.size} ideas: #{ids}. Using most recent."
    }
  end

  resolver.resolve(ref, on_ambiguity: on_ambiguity)
end

#resolve_with_info(ref) ⇒ Hash

Resolve with explicit ambiguity detection

Parameters:

  • ref (String)

    Reference to resolve

Returns:

  • (Hash)

    Result with :result, :ambiguous, :matches keys



40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/ace/idea/molecules/idea_resolver.rb', line 40

def resolve_with_info(ref)
  scan_results = @scanner.scan
  resolver = Ace::Support::Items::Molecules::ShortcutResolver.new(scan_results)

  matches = resolver.all_matches(ref)

  if matches.empty?
    {result: nil, ambiguous: false, matches: []}
  elsif matches.size == 1
    {result: matches.first, ambiguous: false, matches: matches}
  else
    {result: matches.last, ambiguous: true, matches: matches}
  end
end