Class: Processing::Runner
- Inherits:
-
Object
- Object
- Processing::Runner
- Defined in:
- lib/jruby_art/runner.rb
Overview
Utility class to handle the different commands that the ‘k9’ command offers. Able to run, watch, live, create, app, and unpack
Constant Summary collapse
- WIN_PATTERNS =
[ /bccwin/i, /cygwin/i, /djgpp/i, /ming/i, /mswin/i, /wince/i ].freeze
- INSTALL =
<<~MSG.freeze <Config|JRuby-Complete|Samples> or <Sound|Video> library MSG
Instance Attribute Summary collapse
-
#argc ⇒ Object
readonly
Returns the value of attribute argc.
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#os ⇒ Object
readonly
Returns the value of attribute os.
Class Method Summary collapse
-
.execute ⇒ Object
Start running a jruby_art filename from the passed-in arguments.
Instance Method Summary collapse
- #check ⇒ Object
- #create ⇒ Object
-
#execute ⇒ Object
Dispatch central.
-
#export ⇒ Object
Export as app not implemented.
-
#initialize ⇒ Runner
constructor
A new instance of Runner.
- #install(library = nil) ⇒ Object
-
#live ⇒ Object
Just simply run a JRubyArt filename.
-
#parse_options(args) ⇒ Object
Parse the command-line options.
-
#run_sketch ⇒ Object
Just simply run a JRubyArt filename.
-
#show_help ⇒ Object
Show the standard help/usage message.
- #show_version ⇒ Object
-
#watch_sketch ⇒ Object
Run a filename, keeping an eye on it’s file, and reloading whenever it changes.
Constructor Details
#initialize ⇒ Runner
Returns a new instance of Runner.
35 36 37 |
# File 'lib/jruby_art/runner.rb', line 35 def initialize @options = {} end |
Instance Attribute Details
#argc ⇒ Object (readonly)
Returns the value of attribute argc.
33 34 35 |
# File 'lib/jruby_art/runner.rb', line 33 def argc @argc end |
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
33 34 35 |
# File 'lib/jruby_art/runner.rb', line 33 def filename @filename end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
33 34 35 |
# File 'lib/jruby_art/runner.rb', line 33 def @options end |
#os ⇒ Object (readonly)
Returns the value of attribute os.
33 34 35 |
# File 'lib/jruby_art/runner.rb', line 33 def os @os end |
Class Method Details
.execute ⇒ Object
Start running a jruby_art filename from the passed-in arguments
40 41 42 43 44 |
# File 'lib/jruby_art/runner.rb', line 40 def self.execute runner = new runner.(ARGV) runner.execute end |
Instance Method Details
#check ⇒ Object
164 165 166 167 |
# File 'lib/jruby_art/runner.rb', line 164 def check require_relative '../jruby_art/config' Config.new.check end |
#create ⇒ Object
111 112 113 114 |
# 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 |
#execute ⇒ Object
Dispatch central.
47 48 49 50 51 52 53 54 55 56 |
# File 'lib/jruby_art/runner.rb', line 47 def execute ('-h') if .empty? show_version if [:version] run_sketch if [:run] watch_sketch if [:watch] live if [:live] create if [:create] check if [:check] install(filename) if [:install] end |
#export ⇒ Object
Export as app not implemented
117 118 119 120 |
# File 'lib/jruby_art/runner.rb', line 117 def export ensure_exists(filename) puts 'Not implemented yet' end |
#install(library = nil) ⇒ Object
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# 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 [: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 |
#live ⇒ Object
Just simply run a JRubyArt filename.
129 130 131 132 |
# File 'lib/jruby_art/runner.rb', line 129 def live ensure_exists(filename) spin_up('live.rb', filename, argc) end |
#parse_options(args) ⇒ Object
Parse the command-line options.
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 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 |
# File 'lib/jruby_art/runner.rb', line 59 def (args) opt_parser = OptionParser.new do |opts| # Set a banner, displayed at the top # of the help screen. opts. = 'Usage: k9 [options] [<filename.rb>]' # Define the options, and what they do opts.on('-v', '--version', 'JRubyArt Version') do [:version] = true end opts.on('-?', '--check', 'Prints configuration') do [:check] = true end opts.on('-i', '--install', INSTALL) do [:install] = true end opts.on('-f', '--force', 'Force removal of old Config') do [:force] = true end opts.on('-c', '--create', 'Create new outline sketch') do [:create] = true end opts.on('-r', '--run', 'Run the sketch') do [:run] = true end opts.on('-w', '--watch', 'Watch/run the sketch') do [:watch] = true end opts.on('-l', '--live', 'As above, with pry console bound to Processing.app') do [:live] = true end opts.on('-a', '--app', 'Export as app NOT IMPLEMENTED YET') do [: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 |
#run_sketch ⇒ Object
Just simply run a JRubyArt filename.
123 124 125 126 |
# File 'lib/jruby_art/runner.rb', line 123 def run_sketch ensure_exists(filename) spin_up('run.rb', filename, argc) end |
#show_help ⇒ Object
Show the standard help/usage message.
170 171 172 |
# File 'lib/jruby_art/runner.rb', line 170 def show_help puts HELP_INSTALL end |
#show_version ⇒ Object
174 175 176 177 178 179 180 181 182 183 184 185 |
# 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 |
#watch_sketch ⇒ Object
Run a filename, keeping an eye on it’s file, and reloading whenever it changes.
136 137 138 139 |
# File 'lib/jruby_art/runner.rb', line 136 def watch_sketch ensure_exists(filename) spin_up('watch.rb', filename, argc) end |