Class: Ing::Command
- Inherits:
-
Object
- Object
- Ing::Command
- Defined in:
- lib/ing/command.rb
Class Attribute Summary collapse
Instance Attribute Summary collapse
-
#args ⇒ Object
Returns the value of attribute args.
-
#command_class ⇒ Object
Returns the value of attribute command_class.
-
#command_meth ⇒ Object
Returns the value of attribute command_meth.
-
#options ⇒ Object
Returns the value of attribute options.
Class Method Summary collapse
Instance Method Summary collapse
- #classy? ⇒ Boolean
- #describe ⇒ Object
- #execute {|instance| ... } ⇒ Object
- #help ⇒ Object
-
#initialize(klass, *args) ⇒ Command
constructor
A new instance of Command.
- #instance ⇒ Object
- #with_option_parser {|p| ... } ⇒ Object
Constructor Details
#initialize(klass, *args) ⇒ Command
Returns a new instance of Command.
18 19 20 21 22 23 |
# File 'lib/ing/command.rb', line 18 def initialize(klass, *args) self. = (Hash === args.last ? args.pop : {}) self.command_class = klass self.command_meth = extract_method!(args, command_class) self.args = args end |
Class Attribute Details
.parser ⇒ Object
7 8 9 |
# File 'lib/ing/command.rb', line 7 def parser OptionParsers::Trollop end |
Instance Attribute Details
#args ⇒ Object
Returns the value of attribute args.
16 17 18 |
# File 'lib/ing/command.rb', line 16 def args @args end |
#command_class ⇒ Object
Returns the value of attribute command_class.
16 17 18 |
# File 'lib/ing/command.rb', line 16 def command_class @command_class end |
#command_meth ⇒ Object
Returns the value of attribute command_meth.
16 17 18 |
# File 'lib/ing/command.rb', line 16 def command_meth @command_meth end |
#options ⇒ Object
Returns the value of attribute options.
16 17 18 |
# File 'lib/ing/command.rb', line 16 def @options end |
Class Method Details
.execute(klass, *args, &config) ⇒ Object
11 12 13 |
# File 'lib/ing/command.rb', line 11 def execute(klass, *args, &config) new(klass, *args).execute(&config) end |
Instance Method Details
#classy? ⇒ Boolean
25 26 27 |
# File 'lib/ing/command.rb', line 25 def classy? command_class.respond_to?(:new) end |
#describe ⇒ Object
39 40 41 |
# File 'lib/ing/command.rb', line 39 def describe with_option_parser {|p| p.describe} end |
#execute {|instance| ... } ⇒ Object
33 34 35 36 37 |
# File 'lib/ing/command.rb', line 33 def execute yield instance if block_given? classy? ? instance.send(command_meth, *args) : instance.send(command_meth, *args, ) end |
#help ⇒ Object
43 44 45 |
# File 'lib/ing/command.rb', line 43 def help with_option_parser {|p| p.help} end |
#instance ⇒ Object
29 30 31 |
# File 'lib/ing/command.rb', line 29 def instance @instance ||= build_command end |
#with_option_parser {|p| ... } ⇒ Object
47 48 49 50 51 52 |
# File 'lib/ing/command.rb', line 47 def with_option_parser return unless command_class.respond_to?(:specify_options) p = self.class.parser.new command_class.(p.parser) yield p end |