Class: Processing::Runner
- Inherits:
-
Object
- Object
- Processing::Runner
- Defined in:
- lib/ruby-processing/runner.rb
Overview
Utility class to handle the different commands that the ‘rp5’ command offers. Able to run, watch, live, create, app, and unpack
Constant Summary collapse
- WIN_PATTERNS =
[ /bccwin/i, /cygwin/i, /djgpp/i, /mingw/i, /mswin/i, /wince/i ]
Instance Attribute Summary collapse
-
#os ⇒ Object
readonly
Returns the value of attribute os.
Class Method Summary collapse
-
.execute ⇒ Object
Start running a ruby-processing sketch from the passed-in arguments.
Instance Method Summary collapse
-
#app(sketch) ⇒ Object
Generate a cross-platform application of a given Ruby-Processing sketch.
- #check(root_exist, installed) ⇒ Object
-
#create(sketch, args) ⇒ Object
Create a fresh Ruby-Processing sketch, with the necessary boilerplate filled out.
-
#execute! ⇒ Object
Dispatch central.
- #install(root_exist) ⇒ Object
-
#live(sketch, args) ⇒ Object
Run a sketch, opening its guts to IRB, letting you play with it.
-
#parse_options(args) ⇒ Object
Parse the command-line options.
-
#run(sketch, args) ⇒ Object
Just simply run a ruby-processing sketch.
- #setup(choice) ⇒ Object
-
#show_help ⇒ Object
Show the standard help/usage message.
-
#show_version ⇒ Object
Display the current version of Ruby-Processing.
-
#watch(sketch, args) ⇒ Object
Run a sketch, keeping an eye on it’s file, and reloading whenever it changes.
Instance Attribute Details
#os ⇒ Object (readonly)
Returns the value of attribute os.
55 56 57 |
# File 'lib/ruby-processing/runner.rb', line 55 def os @os end |
Class Method Details
.execute ⇒ Object
Start running a ruby-processing sketch from the passed-in arguments
58 59 60 61 62 |
# File 'lib/ruby-processing/runner.rb', line 58 def self.execute runner = new runner.(ARGV) runner.execute! end |
Instance Method Details
#app(sketch) ⇒ Object
Generate a cross-platform application of a given Ruby-Processing sketch.
121 122 123 124 |
# File 'lib/ruby-processing/runner.rb', line 121 def app(sketch) require_relative '../ruby-processing/exporters/application_exporter' Processing::ApplicationExporter.new.export!(sketch) end |
#check(root_exist, installed) ⇒ Object
147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/ruby-processing/runner.rb', line 147 def check(root_exist, installed) show_version root = ' PROCESSING_ROOT = Not Set!!!' unless root_exist root ||= " PROCESSING_ROOT = #{Processing::RP_CONFIG['PROCESSING_ROOT']}" jruby = Processing::RP_CONFIG['JRUBY'] x_off = Processing::RP_CONFIG['X_OFF'] y_off = Processing::RP_CONFIG['Y_OFF'] puts root puts " JRUBY = #{jruby}" unless jruby.nil? puts " X_OFF = #{x_off}" unless x_off.nil? puts " Y_OFF = #{y_off}" unless y_off.nil? puts " jruby-complete installed = #{installed}" end |
#create(sketch, args) ⇒ Object
Create a fresh Ruby-Processing sketch, with the necessary boilerplate filled out.
94 95 96 97 98 99 |
# File 'lib/ruby-processing/runner.rb', line 94 def create(sketch, args) require_relative '../ruby-processing/exporters/creator' return Processing::Inner.new.create!(sketch, args) if .inner return Processing::ClassSketch.new.create!(sketch, args) if .wrap Processing::BasicSketch.new.create!(sketch, args) end |
#execute! ⇒ Object
Dispatch central.
65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/ruby-processing/runner.rb', line 65 def execute! case .action when 'run' then run(.path, .args) when 'watch' then watch(.path, .args) when 'live' then live(.path, .args) when 'create' then create(.path, .args) when 'app' then app(.path) when 'setup' then setup(.path) when /-v/ then show_version when /-h/ then show_help else show_help end end |
#install(root_exist) ⇒ Object
140 141 142 143 144 145 |
# File 'lib/ruby-processing/runner.rb', line 140 def install(root_exist) system "cd #{RP5_ROOT}/vendors && rake" return if root_exist set_processing_root warn 'PROCESSING_ROOT set optimistically, run check to confirm' end |
#live(sketch, args) ⇒ Object
Run a sketch, opening its guts to IRB, letting you play with it.
115 116 117 118 |
# File 'lib/ruby-processing/runner.rb', line 115 def live(sketch, args) ensure_exists(sketch) spin_up('live.rb', sketch, args) end |
#parse_options(args) ⇒ Object
Parse the command-line options. Keep it simple.
81 82 83 84 85 86 87 88 89 90 |
# File 'lib/ruby-processing/runner.rb', line 81 def (args) = OpenStruct.new .wrap = !args.delete('--wrap').nil? .inner = !args.delete('--inner').nil? .jruby = !args.delete('--jruby').nil? .nojruby = !args.delete('--nojruby').nil? .action = args[0] || nil .path = args[1] || File.basename(Dir.pwd + '.rb') .args = args[2..-1] || [] end |
#run(sketch, args) ⇒ Object
Just simply run a ruby-processing sketch.
102 103 104 105 |
# File 'lib/ruby-processing/runner.rb', line 102 def run(sketch, args) ensure_exists(sketch) spin_up('run.rb', sketch, args) end |
#setup(choice) ⇒ Object
126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/ruby-processing/runner.rb', line 126 def setup(choice) proc_root = File.exist?("#{ENV['HOME']}/.rp5rc") case choice when /check/ check(proc_root, File.exist?("#{RP5_ROOT}/lib/ruby/jruby-complete.jar")) when /install/ install(proc_root) when /unpack_samples/ system "cd #{RP5_ROOT}/vendors && rake unpack_samples" else puts 'Usage: rp5 setup [check | install | unpack_samples]' end end |
#show_help ⇒ Object
Show the standard help/usage message.
168 169 170 |
# File 'lib/ruby-processing/runner.rb', line 168 def show_help puts HELP_MESSAGE end |
#show_version ⇒ Object
Display the current version of Ruby-Processing.
163 164 165 |
# File 'lib/ruby-processing/runner.rb', line 163 def show_version puts "Ruby-Processing version #{RubyProcessing::VERSION}" end |
#watch(sketch, args) ⇒ Object
Run a sketch, keeping an eye on it’s file, and reloading whenever it changes.
109 110 111 112 |
# File 'lib/ruby-processing/runner.rb', line 109 def watch(sketch, args) ensure_exists(sketch) spin_up('watch.rb', sketch, args) end |