class Processing::Runner
Utility class to handle the different commands that the 'k9' command offers. Able to run, watch, live, create, app, and unpack
Constants
- INSTALL
- WIN_PATTERNS
Attributes
Public Class Methods
Start running a jruby_art filename from the passed-in arguments
# File lib/jruby_art/runner.rb, line 40 def self.execute runner = new runner.parse_options(ARGV) runner.execute end
# File lib/jruby_art/runner.rb, line 35 def initialize @options = {} end
Public Instance Methods
# File lib/jruby_art/runner.rb, line 164 def check require_relative '../jruby_art/config' Config.new.check end
# File lib/jruby_art/runner.rb, line 111 def create require_relative '../jruby_art/creators/sketch_writer' SketchWriter.new(File.basename(filename, '.rb'), argc).write end
Dispatch central.
# File lib/jruby_art/runner.rb, line 47 def execute parse_options('-h') if options.empty? show_version if options[:version] run_sketch if options[:run] watch_sketch if options[:watch] live if options[:live] create if options[:create] check if options[:check] install(filename) if options[:install] end
Export as app not implemented
# File lib/jruby_art/runner.rb, line 117 def export ensure_exists(filename) puts 'Not implemented yet' end
# File lib/jruby_art/runner.rb, line 141 def install(library = nil) require_relative 'installer' library ||= 'new' choice = library.downcase case choice when /sound|video/ system "cd #{K9_ROOT}/vendors && rake install_#{choice}" when /samples/ system "cd #{K9_ROOT}/vendors && rake install_samples" when /jruby/ system "cd #{K9_ROOT}/vendors && rake" when /config/ remove_old_config if options[:force] Installer.new.install when /new/ # install samples and config JRubyArt system "cd #{K9_ROOT}/vendors && rake" Installer.new.install else warn format('No installer for %<library>s', library: library) end end
Just simply run a JRubyArt
filename.
# File lib/jruby_art/runner.rb, line 129 def live ensure_exists(filename) spin_up('live.rb', filename, argc) end
Parse the command-line options.
# File lib/jruby_art/runner.rb, line 59 def parse_options(args) opt_parser = OptionParser.new do |opts| # Set a banner, displayed at the top # of the help screen. opts.banner = 'Usage: k9 [options] [<filename.rb>]' # Define the options, and what they do opts.on('-v', '--version', 'JRubyArt Version') do options[:version] = true end opts.on('-?', '--check', 'Prints configuration') do options[:check] = true end opts.on('-i', '--install', INSTALL) do options[:install] = true end opts.on('-f', '--force', 'Force removal of old Config') do options[:force] = true end opts.on('-c', '--create', 'Create new outline sketch') do options[:create] = true end opts.on('-r', '--run', 'Run the sketch') do options[:run] = true end opts.on('-w', '--watch', 'Watch/run the sketch') do options[:watch] = true end opts.on('-l', '--live', 'As above, with pry console bound to Processing.app') do options[:live] = true end opts.on('-a', '--app', 'Export as app NOT IMPLEMENTED YET') do options[:export] = true end opts.on_tail('-h', '--help', 'Display this screen') do puts opts exit end end @argc = opt_parser.parse(args) @filename = argc.shift end
Just simply run a JRubyArt
filename.
# File lib/jruby_art/runner.rb, line 123 def run_sketch ensure_exists(filename) spin_up('run.rb', filename, argc) end
Show the standard help/usage message.
# File lib/jruby_art/runner.rb, line 170 def show_help puts HELP_INSTALL end
# File lib/jruby_art/runner.rb, line 174 def show_version require 'erb' warning = 'WARNING: JDK12 is preferred'.freeze if RUBY_PLATFORM == 'java' warn warning unless ENV_JAVA['java.specification.version'].to_i >= 11 end template = ERB.new <<-VERSION JRubyArt version <%= JRubyArt::VERSION %> Ruby version <%= RUBY_VERSION %> VERSION puts template.result(binding) end
Run a filename, keeping an eye on it's file, and reloading whenever it changes.
# File lib/jruby_art/runner.rb, line 136 def watch_sketch ensure_exists(filename) spin_up('watch.rb', filename, argc) end
Private Instance Methods
NB: We really do mean to use 'and' not '&&' for flow control purposes
# File lib/jruby_art/runner.rb, line 203 def ensure_exists(filename) return if FileTest.exist?(filename) puts("Couldn't find: #{filename}") and exit end
# File lib/jruby_art/runner.rb, line 209 def jruby_complete rcomplete = File.join(K9_ROOT, 'lib/ruby/jruby-complete.jar') return [rcomplete] if FileTest.exist?(rcomplete) warn "#{rcomplete} does not exist\nTry running `k9 --install`" exit end
# File lib/jruby_art/runner.rb, line 217 def remove_old_config old_config = File.join((ENV['HOME']).to_s, '.jruby_art', 'config.yml') puts "Removing #{old_config}" system "rm #{old_config}" end
We now build and execute the command arguments in the Launcher
class. Here we only need to supply the starter script, filename and args if any, the Launcher
class checks config (is executable java or jruby?) and for any options in java_args.txt or config
# File lib/jruby_art/runner.rb, line 193 def spin_up(starter_script, filename, argc) launch = Launcher.new( runner: "#{K9_ROOT}/lib/jruby_art/runners/#{starter_script}", args: argc, filename: filename ) launch.cmd end