Class: MotherBrain::Command
- Inherits:
-
Object
- Object
- MotherBrain::Command
- Includes:
- MB::Mixin::Locks, VariaModel
- Defined in:
- lib/mb/command.rb
Defined Under Namespace
Classes: CleanRoom
Instance Attribute Summary collapse
- #plugin ⇒ MB::Plugin readonly
- #scope ⇒ MB::Plugin, MB::Component readonly
- #type ⇒ Symbol readonly
Instance Method Summary collapse
- #description ⇒ String
- #id ⇒ Symbol
-
#initialize(name, scope, &block) ⇒ Command
constructor
A new instance of Command.
-
#invoke(job, environment, node_filter, *args) ⇒ Object
Run the command on the given environment.
Constructor Details
#initialize(name, scope, &block) ⇒ Command
Returns a new instance of Command.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/mb/command.rb', line 27 def initialize(name, scope, &block) set_attribute(:name, name.to_s) @scope = scope case @scope when MB::Plugin @plugin = @scope @type = :plugin when MB::Component @plugin = @scope.plugin @type = :component else raise RuntimeError, "no matching command type for the given scope: #{scope}." end if block_given? dsl_eval(&block) end end |
Instance Attribute Details
#scope ⇒ MB::Plugin, MB::Component (readonly)
19 20 21 |
# File 'lib/mb/command.rb', line 19 def scope @scope end |
#type ⇒ Symbol (readonly)
23 24 25 |
# File 'lib/mb/command.rb', line 23 def type @type end |
Instance Method Details
#description ⇒ String
48 49 50 |
# File 'lib/mb/command.rb', line 48 def description _attributes_.description || "run #{name} command on #{scope.name}" end |
#id ⇒ Symbol
53 54 55 |
# File 'lib/mb/command.rb', line 53 def id self.name.to_sym end |
#invoke(job, environment, node_filter, *args) ⇒ Object
Run the command on the given environment
69 70 71 |
# File 'lib/mb/command.rb', line 69 def invoke(job, environment, node_filter, *args) CommandRunner.new(job, environment, scope, execute, node_filter, *args) end |