Class: Scripting::Application
- Inherits:
-
Object
- Object
- Scripting::Application
- Extended by:
- Pluggable
- Defined in:
- lib/scripting/application.rb
Instance Method Summary collapse
- #clear_help! ⇒ Object
- #clear_options! ⇒ Object
- #clear_switches! ⇒ Object
- #clear_work! ⇒ Object
- #context ⇒ Object
- #describe(&blk) ⇒ Object
- #help(&blk) ⇒ Object
- #help! ⇒ Object
-
#initialize ⇒ Application
constructor
A new instance of Application.
- #options(&blk) ⇒ Object
- #parse!(args) ⇒ Object
- #run!(*args) ⇒ Object
- #switches(&blk) ⇒ Object
- #work(&blk) ⇒ Object
Methods included from Pluggable
Constructor Details
#initialize ⇒ Application
Returns a new instance of Application.
11 12 13 14 15 16 |
# File 'lib/scripting/application.rb', line 11 def initialize clear_switches! clear_work! clear_help! end |
Instance Method Details
#clear_help! ⇒ Object
54 55 56 |
# File 'lib/scripting/application.rb', line 54 def clear_help! @help = [lambda { $stderr.puts @switches }] end |
#clear_options! ⇒ Object
36 37 38 |
# File 'lib/scripting/application.rb', line 36 def @options = Options.new end |
#clear_switches! ⇒ Object
27 28 29 |
# File 'lib/scripting/application.rb', line 27 def clear_switches! @switches = Parser.new(self) end |
#clear_work! ⇒ Object
45 46 47 |
# File 'lib/scripting/application.rb', line 45 def clear_work! @work = [] end |
#context ⇒ Object
18 19 20 |
# File 'lib/scripting/application.rb', line 18 def context self end |
#describe(&blk) ⇒ Object
22 23 24 25 |
# File 'lib/scripting/application.rb', line 22 def describe &blk instance_eval &blk if block_given? self end |
#help(&blk) ⇒ Object
58 59 60 61 |
# File 'lib/scripting/application.rb', line 58 def help &blk @help << blk if block_given? @help end |
#help! ⇒ Object
63 64 65 |
# File 'lib/scripting/application.rb', line 63 def help! @help.each(&:call) end |
#options(&blk) ⇒ Object
40 41 42 43 |
# File 'lib/scripting/application.rb', line 40 def &blk @options.describe &blk if block_given? @options end |
#parse!(args) ⇒ Object
67 68 69 70 |
# File 'lib/scripting/application.rb', line 67 def parse! args switches.parse! args args end |
#run!(*args) ⇒ Object
72 73 74 75 76 77 78 |
# File 'lib/scripting/application.rb', line 72 def run! *args if args.first.kind_of? Array args.flatten! end parse! args work.each { |work| instance_exec(*args, &work) } end |
#switches(&blk) ⇒ Object
31 32 33 34 |
# File 'lib/scripting/application.rb', line 31 def switches &blk @switches.instance_eval &blk if block_given? @switches end |
#work(&blk) ⇒ Object
49 50 51 52 |
# File 'lib/scripting/application.rb', line 49 def work &blk @work << blk if block_given? @work end |