Class: Scripting::Commands::Command
- Inherits:
-
Object
- Object
- Scripting::Commands::Command
- Defined in:
- lib/scripting/commands.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #describe(&blk) ⇒ Object
- #description(desc = nil) ⇒ Object
-
#initialize(app, name) ⇒ Command
constructor
A new instance of Command.
- #run!(*args) ⇒ Object
- #work(&blk) ⇒ Object
Constructor Details
#initialize(app, name) ⇒ Command
Returns a new instance of Command.
7 8 9 10 11 12 |
# File 'lib/scripting/commands.rb', line 7 def initialize app, name @app = app @name = name.to_s.downcase.to_sym @description = nil @work = lambda {} # noop by default end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/scripting/commands.rb', line 5 def name @name end |
Instance Method Details
#describe(&blk) ⇒ Object
14 15 16 17 |
# File 'lib/scripting/commands.rb', line 14 def describe &blk instance_eval &blk if block_given? self end |
#description(desc = nil) ⇒ Object
19 20 21 22 23 24 |
# File 'lib/scripting/commands.rb', line 19 def description desc=nil unless desc.nil? @description = desc end @description end |
#run!(*args) ⇒ Object
31 32 33 |
# File 'lib/scripting/commands.rb', line 31 def run! *args @app.instance_exec(*args, &work) end |
#work(&blk) ⇒ Object
26 27 28 29 |
# File 'lib/scripting/commands.rb', line 26 def work &blk @work = blk if block_given? @work end |