Class: TyrantManager::Command
- Inherits:
-
Object
- Object
- TyrantManager::Command
- Defined in:
- lib/tyrant_manager/command.rb
Overview
The Command is the base class for any class to be used as a command
All commands run within the context of an existing TyrantManager location. Before the command starts the current working directory will be inside the tyrant manager’s home directory.
A command has a lifecyle of:
-
instantiation with a TyrantManager instance and an options hash
-
one call to before
-
one call to run
-
one call to after
In case of an exception raised during the lifecycle, the error
method will be called. The after
method is called no matter what at the end of the lifecycle, even if an error has occurred.
Direct Known Subclasses
TyrantManager::Commands::ArchiveUlogs, TyrantManager::Commands::CreateInstance, TyrantManager::Commands::List, TyrantManager::Commands::ProcessStatus, TyrantManager::Commands::ReplicationStatus, TyrantManager::Commands::Start, TyrantManager::Commands::Stats, TyrantManager::Commands::Stop
Defined Under Namespace
Classes: CommandNotFoundError
Instance Attribute Summary collapse
-
#manager ⇒ Object
readonly
Returns the value of attribute manager.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
Instance Method Summary collapse
-
#after ⇒ Object
call-seq: cmd.after.
-
#before ⇒ Object
call-seq: cmd.before.
- #command_name ⇒ Object
-
#error(exception) ⇒ Object
call-seq: cmd.error( exception ).
-
#initialize(manager, opts = {}) ⇒ Command
constructor
Instantiated and given the tyrant manager instance it is to operate through and a hash of options.
- #logger ⇒ Object
-
#run ⇒ Object
call-seq: cmd.run.
Constructor Details
#initialize(manager, opts = {}) ⇒ Command
Instantiated and given the tyrant manager instance it is to operate through and a hash of options
38 39 40 41 |
# File 'lib/tyrant_manager/command.rb', line 38 def initialize( manager, opts = {} ) @manager = manager @options = opts end |
Instance Attribute Details
#manager ⇒ Object (readonly)
Returns the value of attribute manager.
32 33 34 |
# File 'lib/tyrant_manager/command.rb', line 32 def manager @manager end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
31 32 33 |
# File 'lib/tyrant_manager/command.rb', line 31 def @options end |
Class Method Details
.command_name ⇒ Object
27 28 29 |
# File 'lib/tyrant_manager/command.rb', line 27 def self.command_name name.split("::").last.downcase end |
.find(command) ⇒ Object
109 110 111 112 113 114 |
# File 'lib/tyrant_manager/command.rb', line 109 def find( command ) klass = list.find { |klass| klass.command_name == command } return klass if klass names = list.collect { |c| c.command_name } raise CommandNotFoundError, "No command for '#{command}' was found. Known commands : #{names.join(",")}" end |
.inherited(klass) ⇒ Object
97 98 99 100 |
# File 'lib/tyrant_manager/command.rb', line 97 def inherited( klass ) return unless klass.instance_of? Class self.list << klass end |
.list ⇒ Object
102 103 104 105 106 107 |
# File 'lib/tyrant_manager/command.rb', line 102 def list unless defined? @list @list = Set.new end return @list end |
Instance Method Details
#after ⇒ Object
call-seq:
cmd.after
called no matter what, after the execution of run() or error() if there was an exception. It is here to allow the cmd to do cleanup work.
81 |
# File 'lib/tyrant_manager/command.rb', line 81 def after() nil ; end |
#before ⇒ Object
call-seq:
cmd.before
called to allow the command to setup anything post initialization it needs to be able to run
.
62 |
# File 'lib/tyrant_manager/command.rb', line 62 def before() nil ; end |
#command_name ⇒ Object
43 44 45 |
# File 'lib/tyrant_manager/command.rb', line 43 def command_name self.class.command_name end |
#error(exception) ⇒ Object
call-seq:
cmd.error( exception )
called if there is an exception during the before() or after() calls. It is passed in the exception that was raised.
90 |
# File 'lib/tyrant_manager/command.rb', line 90 def error(exception) nil ; end |
#logger ⇒ Object
47 48 49 |
# File 'lib/tyrant_manager/command.rb', line 47 def logger Logging::Logger[self] end |
#run ⇒ Object
call-seq:
cmd.run
Yeah, this is where the work should be done.
70 71 72 |
# File 'lib/tyrant_manager/command.rb', line 70 def run() raise NotImplementedError, "The #run method must be implemented" end |