Class: Propane::Runner
- Inherits:
-
Object
- Object
- Propane::Runner
- Defined in:
- lib/propane/runner.rb
Overview
Utility class to handle the different commands that the 'propane' 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 propane 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) ⇒ Object
-
#parse_options(args) ⇒ Object
Parse the command-line options.
- #show_version ⇒ Object
Constructor Details
#initialize ⇒ Runner
Returns a new instance of Runner.
10 11 12 |
# File 'lib/propane/runner.rb', line 10 def initialize @options = {} end |
Instance Attribute Details
#argc ⇒ Object (readonly)
Returns the value of attribute argc.
8 9 10 |
# File 'lib/propane/runner.rb', line 8 def argc @argc end |
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
8 9 10 |
# File 'lib/propane/runner.rb', line 8 def filename @filename end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
8 9 10 |
# File 'lib/propane/runner.rb', line 8 def @options end |
Class Method Details
.execute ⇒ Object
Start running a propane command from the passed-in arguments
15 16 17 18 19 |
# File 'lib/propane/runner.rb', line 15 def self.execute runner = new runner.(ARGV) runner.execute! end |
Instance Method Details
#create ⇒ Object
64 65 66 67 |
# File 'lib/propane/runner.rb', line 64 def create require_relative 'creators/sketch_writer' SketchWriter.new(File.basename(filename, '.rb'), argc).write end |
#execute! ⇒ Object
Dispatch central.
22 23 24 25 26 27 |
# File 'lib/propane/runner.rb', line 22 def execute! show_help if .empty? show_version if [:version] create if [:create] install(filename) if [:install] end |
#install(library) ⇒ Object
74 75 76 77 78 79 |
# File 'lib/propane/runner.rb', line 74 def install(library) choice = library.downcase valid = Regexp.union('samples', 'sound', 'video', 'glvideo') return warn format('No installer for %s', choice) unless valid =~ choice system "cd #{PROPANE_ROOT}/vendors && rake download_and_copy_#{choice}" end |
#parse_options(args) ⇒ Object
Parse the command-line options. Keep it simple.
30 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 |
# File 'lib/propane/runner.rb', line 30 def (args) opt_parser = OptionParser.new do |opts| # Set a banner, displayed at the top # of the help screen. opts. = 'Usage: propane [options] [<sketch.rb>]' # Define the options, and what they do [:version] = false opts.on('-v', '--version', 'Propane Version') do [:version] = true end [:install] = false = '<Samples><GLVideo><Video><Sound> 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('-h', '--help', 'Display this screen') do puts opts exit end end @argc = opt_parser.parse(args) @filename = argc.shift end |