Class: RubySpriter::DependencyChecker

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_spriter/dependency_checker.rb

Overview

Checks for required external dependencies

Constant Summary collapse

REQUIRED_TOOLS =
{
  ffmpeg: {
    command: 'ffmpeg -version',
    pattern: /ffmpeg version/i,
    install: {
      windows: 'choco install ffmpeg',
      linux: 'sudo apt install ffmpeg',
      macos: 'brew install ffmpeg'
    }
  },
  ffprobe: {
    command: 'ffprobe -version',
    pattern: /ffprobe version/i,
    install: {
      windows: 'Included with ffmpeg',
      linux: 'Included with ffmpeg',
      macos: 'Included with ffmpeg'
    }
  },
  imagemagick: {
    command: Platform.imagemagick_identify_cmd + ' -version',
    pattern: /ImageMagick/i,
    install: {
      windows: 'choco install imagemagick',
      linux: 'sudo apt install imagemagick',
      macos: 'brew install imagemagick'
    }
  },
  xvfb: {
    command: 'xvfb-run --help',
    pattern: /xvfb-run/i,
    install: {
      windows: 'Not required on Windows',
      linux: 'sudo apt install xvfb',
      macos: 'Not required on macOS'
    },
    optional_for: [:windows, :macos]  # Only required on Linux
  }
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(verbose: false) ⇒ DependencyChecker

Returns a new instance of DependencyChecker.



48
49
50
51
52
# File 'lib/ruby_spriter/dependency_checker.rb', line 48

def initialize(verbose: false)
  @verbose = verbose
  @gimp_path = nil
  @gimp_version = nil
end

Instance Attribute Details

#gimp_pathObject (readonly)

Get the found GIMP executable path



116
117
118
# File 'lib/ruby_spriter/dependency_checker.rb', line 116

def gimp_path
  @gimp_path
end

#gimp_versionObject (readonly)

Get the detected GIMP version info



119
120
121
# File 'lib/ruby_spriter/dependency_checker.rb', line 119

def gimp_version
  @gimp_version
end

Instance Method Details

#all_satisfied?Boolean

Check if all dependencies are satisfied

Returns:

  • (Boolean)

    true if all dependencies are available



70
71
72
73
# File 'lib/ruby_spriter/dependency_checker.rb', line 70

def all_satisfied?
  results = check_all
  results.all? { |tool, status| status[:available] || status[:optional] }
end

#check_allHash

Check all dependencies

Returns:

  • (Hash)

    Results of dependency checks



56
57
58
59
60
61
62
63
64
65
66
# File 'lib/ruby_spriter/dependency_checker.rb', line 56

def check_all
  results = {}
  
  REQUIRED_TOOLS.each do |tool, config|
    results[tool] = check_tool(tool, config)
  end

  results[:gimp] = check_gimp

  results
end

Print dependency status report



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/ruby_spriter/dependency_checker.rb', line 76

def print_report
  results = check_all
  
  puts "\n" + "=" * 60
  puts "Dependency Check"
  puts "=" * 60
  
  results.each do |tool, status|
    if status[:optional] && !status[:available]
      icon = ""
      optional_text = " (Optional for #{Platform.current})"
    else
      icon = status[:available] ? "" : ""
      optional_text = ""
    end

    puts "\n#{icon} #{tool.to_s.upcase}#{optional_text}"

    if status[:available]
      if tool == :gimp && status[:version]
        version_str = "GIMP #{status[:version][:full]}"
        puts "   Found: #{status[:path]}"
        puts "   Version: #{version_str}"
      else
        puts "   Found: #{status[:path] || status[:version]}"
      end
    else
      if status[:optional]
        puts "   Status: NOT FOUND (not required for this platform)"
      else
        puts "   Status: NOT FOUND"
        puts "   Install: #{status[:install_cmd]}"
      end
    end
  end
  
  puts "\n" + "=" * 60 + "\n"
end