Class: Roast::Workflow::ResourceResolver

Inherits:
Object
  • Object
show all
Defined in:
lib/roast/workflow/resource_resolver.rb

Overview

Handles resource resolution and target processing Extracts file/resource handling logic from Configuration

Class Method Summary collapse

Class Method Details

.process_shell_command(command) ⇒ String

Process shell commands in $(command) or legacy % format

Parameters:

  • command (String)

    The command string

Returns:

  • (String)

    The command output or original string if not a shell command



51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/roast/workflow/resource_resolver.rb', line 51

def process_shell_command(command)
  # If it's a bash command with the $(command) syntax
  if command =~ /^\$\((.*)\)$/
    return Open3.capture2e({}, ::Regexp.last_match(1)).first.strip
  end

  # Legacy % prefix for backward compatibility
  if command.start_with?("% ")
    return Open3.capture2e({}, *command.split(" ")[1..-1]).first.strip
  end

  # Not a shell command, return as is
  command
end

.process_target(target, context_path) ⇒ String

Process target through shell command expansion and glob pattern matching

Parameters:

  • target (String)

    The raw target string

  • context_path (String)

    The directory containing the workflow file

Returns:

  • (String)

    The processed target



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/roast/workflow/resource_resolver.rb', line 24

def process_target(target, context_path)
  # Process shell command first
  processed = process_shell_command(target)

  # If it's a glob pattern, return the full paths of the files it matches
  if processed.include?("*")
    matched_files = Dir.glob(processed)
    # If no files match, return the pattern itself
    return processed if matched_files.empty?

    return matched_files.map { |file| File.expand_path(file) }.join("\n")
  end

  # For tests, if the command was already processed as a shell command and is simple,
  # don't expand the path to avoid breaking existing tests
  return processed if target != processed && !processed.include?("/")

  # Don't expand URLs
  return processed if processed.match?(%r{^https?://})

  # assumed to be a direct file path
  File.expand_path(processed)
end

.resolve(target, context_path) ⇒ Roast::Resources::BaseResource

Process the target and create appropriate resource object

Parameters:

  • target (String, nil)

    The target from configuration or options

  • context_path (String)

    The directory containing the workflow file

Returns:



13
14
15
16
17
18
# File 'lib/roast/workflow/resource_resolver.rb', line 13

def resolve(target, context_path)
  return Roast::Resources::NoneResource.new(nil) unless has_target?(target)

  processed_target = process_target(target, context_path)
  Roast::Resources.for(processed_target)
end