Class: Amp::Command::Base
- Includes:
- Validations
- Defined in:
- lib/amp-front/dispatch/commands/base.rb
Overview
The base class frmo which all comamnds inherit.
Class Attribute Summary collapse
-
.desc(*args) ⇒ Object
Returns the value of attribute desc.
-
.name ⇒ Object
Returns the value of attribute name.
-
.options ⇒ Object
Returns the value of attribute options.
Instance Attribute Summary collapse
-
#arguments ⇒ Object
These are the runtime options selected when the command is called.
-
#options ⇒ Object
These are the runtime options selected when the command is called.
Class Method Summary collapse
-
.all_commands ⇒ Object
This tracks all subclasses (and subclasses of subclasses, etc).
-
.inherited(klass) ⇒ Object
When a Plugin subclass is subclassed, store the subclass and inform the next superclass up the inheritance hierarchy.
-
.on_call(&block) ⇒ Object
Specifies the block to run, or returns the block.
- .opt(*args) ⇒ Object
Instance Method Summary collapse
-
#call(opts, args) ⇒ Object
Runs the command with the provided options and arguments.
-
#collect_options(input_args) ⇒ Object
Collects the options specific to this command and returns them.
- #education ⇒ Object
Methods included from Validations
included, #invalid?, #run_after, #valid?
Class Attribute Details
.desc(*args) ⇒ Object
Returns the value of attribute desc.
79 80 81 |
# File 'lib/amp-front/dispatch/commands/base.rb', line 79 def desc @desc end |
.name ⇒ Object
Returns the value of attribute name.
79 80 81 |
# File 'lib/amp-front/dispatch/commands/base.rb', line 79 def name @name end |
.options ⇒ Object
Returns the value of attribute options.
79 80 81 |
# File 'lib/amp-front/dispatch/commands/base.rb', line 79 def @options end |
Instance Attribute Details
#arguments ⇒ Object
These are the runtime options selected when the command is called.
84 85 86 |
# File 'lib/amp-front/dispatch/commands/base.rb', line 84 def arguments @arguments end |
#options ⇒ Object
These are the runtime options selected when the command is called.
84 85 86 |
# File 'lib/amp-front/dispatch/commands/base.rb', line 84 def @options end |
Class Method Details
.all_commands ⇒ Object
This tracks all subclasses (and subclasses of subclasses, etc). Plus, this method is inherited, so Wool::Plugins::Git.all_subclasses will have all subclasses of Wool::Plugins::Git!
89 90 91 |
# File 'lib/amp-front/dispatch/commands/base.rb', line 89 def self.all_commands @all_commands ||= [self] end |
.inherited(klass) ⇒ Object
When a Plugin subclass is subclassed, store the subclass and inform the next superclass up the inheritance hierarchy.
95 96 97 98 99 100 101 102 103 |
# File 'lib/amp-front/dispatch/commands/base.rb', line 95 def self.inherited(klass) klass.name ||= 'anonymous ' + self.name self.all_commands << klass next_klass = self.superclass while next_klass != Amp::Command::Base.superclass next_klass.send(:inherited, klass) next_klass = next_klass.superclass end end |
.on_call(&block) ⇒ Object
Specifies the block to run, or returns the block.
106 107 108 109 110 |
# File 'lib/amp-front/dispatch/commands/base.rb', line 106 def self.on_call(&block) if block_given? define_method :call_without_args, &block end end |
.opt(*args) ⇒ Object
121 122 123 |
# File 'lib/amp-front/dispatch/commands/base.rb', line 121 def self.opt(*args) self. << args end |
Instance Method Details
#call(opts, args) ⇒ Object
Runs the command with the provided options and arguments.
126 127 128 129 130 |
# File 'lib/amp-front/dispatch/commands/base.rb', line 126 def call(opts, args) self. = opts self.arguments = args call_without_args end |
#collect_options(input_args) ⇒ Object
Collects the options specific to this command and returns them.
133 134 135 136 137 138 139 140 141 142 |
# File 'lib/amp-front/dispatch/commands/base.rb', line 133 def (input_args) args = input_args.dup = self.class. # Trollop::options uses instance_eval @parser, hash = Trollop::(args) do .each do |option| opt *option end end [hash, args] end |
#education ⇒ Object
144 145 146 147 148 149 150 151 152 |
# File 'lib/amp-front/dispatch/commands/base.rb', line 144 def education if @parser output = StringIO.new @parser.educate(output) output.string else '' end end |