Class: Processing::Runner
- Inherits:
-
Object
- Object
- Processing::Runner
- Defined in:
- lib/picrate/runner.rb
Overview
Utility class to handle the different commands that the ‘picrate’ offers
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.
Class Method Summary collapse
-
.execute ⇒ Object
Start running a picrate command from the passed-in arguments.
Instance Method Summary collapse
- #create ⇒ Object
-
#execute ⇒ Object
Dispatch central.
-
#initialize ⇒ Runner
constructor
A new instance of Runner.
- #install(library = nil) ⇒ Object
-
#parse_options(args) ⇒ Object
Parse the command-line options.
- #show_version ⇒ Object
Constructor Details
permalink #initialize ⇒ Runner
Returns a new instance of Runner.
11 12 13 |
# File 'lib/picrate/runner.rb', line 11 def initialize @options = {} end |
Instance Attribute Details
permalink #argc ⇒ Object (readonly)
Returns the value of attribute argc.
9 10 11 |
# File 'lib/picrate/runner.rb', line 9 def argc @argc end |
permalink #filename ⇒ Object (readonly)
Returns the value of attribute filename.
9 10 11 |
# File 'lib/picrate/runner.rb', line 9 def filename @filename end |
permalink #options ⇒ Object (readonly)
Returns the value of attribute options.
9 10 11 |
# File 'lib/picrate/runner.rb', line 9 def @options end |
Class Method Details
permalink .execute ⇒ Object
Start running a picrate command from the passed-in arguments
16 17 18 19 20 |
# File 'lib/picrate/runner.rb', line 16 def self.execute runner = new runner.(ARGV) runner.execute end |
Instance Method Details
permalink #create ⇒ Object
[View source]
67 68 69 70 71 |
# File 'lib/picrate/runner.rb', line 67 def create require_relative 'creators/sketch_writer' # in case user supplied extension, we remove it SketchWriter.new(File.basename(filename, '.rb')).write end |
permalink #execute ⇒ Object
Dispatch central.
23 24 25 26 27 28 |
# File 'lib/picrate/runner.rb', line 23 def execute ('-h') if .empty? show_version if [:version] create if [:create] install(filename) if [:install] end |
permalink #install(library = nil) ⇒ Object
[View source]
82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/picrate/runner.rb', line 82 def install(library = nil) library ||= 'new' choice = library.downcase case choice when /samples|sound|video/ system "cd #{PICRATE_ROOT}/vendors && rake install_#{choice}" when /new/ # install samples and config geany system "cd #{PICRATE_ROOT}/vendors && rake" else warn format('No installer for %s', library) end end |
permalink #parse_options(args) ⇒ Object
Parse the command-line options. Keep it simple.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/picrate/runner.rb', line 31 def (args) opt_parser = OptionParser.new do |opts| # Set a banner, displayed at the top # of the help screen. opts. = 'Usage: picrate [options] [<name>]' # Define the options, and what they do [:version] = false opts.on('-v', '--version', 'PiCrate Version') do [:version] = true end [:install] = false = '<Samples><Video> Install samples or library' opts.on('-i', '--install', ) do [:install] = true end [:create] = false opts.on('-c', '--create', 'Create new sketch outline') do [:create] = true end # This displays the help screen, all programs are # assumed to have this option. opts.on_tail('-h', '--help', 'Display this screen') do puts opts puts '' puts 'Run a sketch: jruby [--dev] [<sketch.rb>]' exit end end @argc = opt_parser.parse(args) @filename = argc.shift end |
permalink #show_version ⇒ Object
[View source]
73 74 75 76 77 78 79 80 |
# File 'lib/picrate/runner.rb', line 73 def show_version require 'erb' template = ERB.new <<-EOF PiCrate version <%= PiCrate::VERSION %> JRuby version <%= JRUBY_VERSION %> EOF puts template.result(binding) end |