Class: Processing::Runner

Inherits:
Object
  • Object
show all
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,
  /ming/i,
  /mswin/i,
  /wince/i
]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#osObject (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

.executeObject

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.parse_options(ARGV)
  runner.execute!
end

Instance Method Details

#app(sketch) ⇒ Object

Generate a cross-platform application of a given Ruby-Processing sketch.



127
128
129
130
# File 'lib/ruby-processing/runner.rb', line 127

def app(sketch)
  require_relative '../ruby-processing/exporters/application_exporter'
  Processing::ApplicationExporter.new.export!(sketch)
end

#check(root_exist, installed) ⇒ Object



153
154
155
156
157
158
159
160
161
162
163
164
165
# File 'lib/ruby-processing/runner.rb', line 153

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.



95
96
97
98
99
100
# File 'lib/ruby-processing/runner.rb', line 95

def create(sketch, args)
  require_relative '../ruby-processing/exporters/creator'
  return Processing::Inner.new.create!(sketch, args) if @options.inner
  return Processing::ClassSketch.new.create!(sketch, args) if @options.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
79
# File 'lib/ruby-processing/runner.rb', line 65

def execute!
  case @options.action
  when 'run'        then run(@options.path, @options.args)
  when 'run-app'    then run_app(@options.path, @options.args)
  when 'watch'      then watch(@options.path, @options.args)
  when 'live'       then live(@options.path, @options.args)
  when 'create'     then create(@options.path, @options.args)
  when 'app'        then app(@options.path)
  when 'setup'      then setup(@options.path)
  when /-v/         then show_version
  when /-h/         then show_help
  else
    show_help
  end
end

#install(root_exist) ⇒ Object



146
147
148
149
150
151
# File 'lib/ruby-processing/runner.rb', line 146

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.



121
122
123
124
# File 'lib/ruby-processing/runner.rb', line 121

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.



82
83
84
85
86
87
88
89
90
91
# File 'lib/ruby-processing/runner.rb', line 82

def parse_options(args)
  @options = OpenStruct.new
  @options.wrap = !args.delete('--wrap').nil?
  @options.inner = !args.delete('--inner').nil?
  @options.jruby = !args.delete('--jruby').nil?
  @options.nojruby = !args.delete('--nojruby').nil?
  @options.action = args[0] || nil
  @options.path = args[1] || File.basename(Dir.pwd + '.rb')
  @options.args = args[2..-1] || []
end

#run(sketch, args) ⇒ Object

Just simply run a ruby-processing sketch.



103
104
105
106
# File 'lib/ruby-processing/runner.rb', line 103

def run(sketch, args)
  ensure_exists(sketch)
  spin_up('run.rb', sketch, args)
end

#run_app(sketch, args) ⇒ Object



108
109
110
111
# File 'lib/ruby-processing/runner.rb', line 108

def run_app(sketch, args)
  ensure_exists(sketch)
  spin_up('run_app.rb', sketch, args)
end

#setup(choice) ⇒ Object



132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/ruby-processing/runner.rb', line 132

def setup(choice)
  proc_root = FileTest.exist?("#{ENV['HOME']}/.rp5rc")
  case choice
  when /check/
    check(proc_root, FileTest.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_helpObject

Show the standard help/usage message.



173
174
175
# File 'lib/ruby-processing/runner.rb', line 173

def show_help
  puts HELP_MESSAGE
end

#show_versionObject

Display the current version of Ruby-Processing.



168
169
170
# File 'lib/ruby-processing/runner.rb', line 168

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.



115
116
117
118
# File 'lib/ruby-processing/runner.rb', line 115

def watch(sketch, args)
  ensure_exists(sketch)
  spin_up('watch.rb', sketch, args)
end