Class: Processing::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/jruby_art/runner.rb

Constant Summary collapse

WIN_PATTERNS =
[
  /bccwin/i,
  /cygwin/i,
  /djgpp/i,
  /ming/i,
  /mswin/i,
  /wince/i
].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRunner

Returns a new instance of Runner.



30
31
32
# File 'lib/jruby_art/runner.rb', line 30

def initialize
  @options = {}
end

Instance Attribute Details

#argcObject (readonly)

Returns the value of attribute argc.



28
29
30
# File 'lib/jruby_art/runner.rb', line 28

def argc
  @argc
end

#filenameObject (readonly)

Returns the value of attribute filename.



28
29
30
# File 'lib/jruby_art/runner.rb', line 28

def filename
  @filename
end

#optionsObject (readonly)

Returns the value of attribute options.



28
29
30
# File 'lib/jruby_art/runner.rb', line 28

def options
  @options
end

#osObject (readonly)

Returns the value of attribute os.



28
29
30
# File 'lib/jruby_art/runner.rb', line 28

def os
  @os
end

Class Method Details

.executeObject

Start running a jruby_art filename from the passed-in arguments



35
36
37
38
39
# File 'lib/jruby_art/runner.rb', line 35

def self.execute
  runner = new
  runner.parse_options(ARGV)
  runner.execute!
end

Instance Method Details

#checkObject



148
149
150
151
# File 'lib/jruby_art/runner.rb', line 148

def check
  require_relative '../jruby_art/config'
  Config.new.check
end

#createObject



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.



42
43
44
45
46
47
48
49
50
51
# File 'lib/jruby_art/runner.rb', line 42

def execute!
  show_help 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 if options[:install]
end

#exportObject

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

#installObject



141
142
143
144
145
146
# File 'lib/jruby_art/runner.rb', line 141

def install
  require_relative 'installer'
  Installer.new.install
  JRubyCompleteInstall.new.install
  UnpackSamples.new.install
end

#liveObject

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.



54
55
56
57
58
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 54

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
    options[:version] = false
    opts.on('-v', '--version', 'JRubyArt Version') do
      options[:version] = true
    end

    options[:install] = false
    opts.on('-i', '--install', 'Installs jruby-complete and examples') do
      options[:install] = true
    end

    options[:check] = false
    opts.on('-?', '--check', 'Prints configuration') do
      options[:check] = true
    end

    options[:app] = false
    opts.on('-a', '--app', 'Export as app NOT IMPLEMENTED YET') do
      options[:export] = true
    end

    options[:watch] = false
    opts.on('-w', '--watch', 'Watch/run the sketch') do
      options[:watch] = true
    end

    options[:run] = false
    opts.on('-r', '--run', 'Run the sketch') do
      options[:run] = true
    end

    options[:live] = false
    opts.on('-l', '--live', 'As above, with pry console bound to Processing.app') do
      options[:live] = true
    end

    options[:create] = false
    opts.on('-c', '--create', 'Create new outline sketch') do
      options[:create] = true
    end

    # This displays the help screen, all programs are
    # assumed to have this option.
    opts.on('-h', '--help', 'Display this screen') do
      puts opts
      exit
    end
  end
  @argc = opt_parser.parse(args)
  @filename = argc.shift
end

#run_sketchObject

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_helpObject

Show the standard help/usage message.



154
155
156
# File 'lib/jruby_art/runner.rb', line 154

def show_help
  puts HELP_MESSAGE
end

#show_versionObject



158
159
160
161
162
163
164
165
166
167
168
169
# File 'lib/jruby_art/runner.rb', line 158

def show_version
  require 'erb'
  warning = 'WARNING: JDK11 is preferred'.freeze
  if RUBY_PLATFORM == 'java'
    warn warning unless ENV_JAVA['java.specification.version'] == '11'
  end
  template = ERB.new <<-EOF
    JRubyArt version <%= JRubyArt::VERSION %>
    Ruby version <%= RUBY_VERSION %>
  EOF
  puts template.result(binding)
end

#watch_sketchObject

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