Class: Trooper::Action
- Inherits:
-
Object
- Object
- Trooper::Action
- Includes:
- DSL::Bundler, DSL::Folders, DSL::Rake
- Defined in:
- lib/trooper/action.rb
Direct Known Subclasses
Trooper::Actions::CloneRepositoryAction, Trooper::Actions::InstallGemsAction, Trooper::Actions::MigrateDatabaseAction, Trooper::Actions::PreparePrerequisiteAction, Trooper::Actions::RestartServerAction, Trooper::Actions::RollbackMigrateAction, Trooper::Actions::SetupDatabaseAction, Trooper::Actions::SetupTrooperAction, Trooper::Actions::UpdateRepositoryAction
Instance Attribute Summary (collapse)
-
- (Object) block
readonly
Returns the value of attribute block.
-
- (Object) commands
Returns the value of attribute commands.
-
- (Object) config
readonly
Returns the value of attribute config.
-
- (Object) description
readonly
Returns the value of attribute description.
-
- (Object) name
readonly
Returns the value of attribute name.
-
- (Object) options
readonly
Returns the value of attribute options.
Instance Method Summary (collapse)
-
- (Object) call(configuration)
(also: #execute)
Public: Eval's the block passed on initialize.
-
- (Action) initialize(name, description, options = {}, &block)
constructor
Public: Define a new action.
-
- (Object) method_missing(method_sym, *arguments, &block)
:nodoc:.
-
- (Boolean) ok?
Public: Validates the action object.
-
- (Object) prerequisite_call(configuration)
Public: Modifies the commands list to include the prerequisite list checker .
-
- (Object) run(command)
Public: Appends command(string) to commands(array).
-
- (Object) type
Public: What type of action this is.
Methods included from DSL::Bundler
#bundle_exec, #bundle_install, #rake
Methods included from DSL::Rake
Methods included from DSL::Folders
#cd, #create_folder, #create_folders, #delete_folder
Constructor Details
- (Action) initialize(name, description, options = {}, &block)
Public: Define a new action.
name - The name of the action. description - A description of action to be used in the cli output. options - The Hash options used to refine the selection (default: {}):
:local - A boolean of whether this action should be run locally (optional).
block - A block containing the tasks to run in this action.
Examples
Action.new(:my_action, 'Does great things') { run 'touch file' }
Returns a new action object.
27 28 29 30 |
# File 'lib/trooper/action.rb', line 27 def initialize(name, description, = {}, &block) @name, @description, @options, @config = name, description, , {} @commands, @block = [], block end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
- (Object) method_missing(method_sym, *arguments, &block)
:nodoc:
103 104 105 |
# File 'lib/trooper/action.rb', line 103 def method_missing(method_sym, *arguments, &block) # :nodoc: config[method_sym] || super end |
Instance Attribute Details
- (Object) block (readonly)
Returns the value of attribute block
11 12 13 |
# File 'lib/trooper/action.rb', line 11 def block @block end |
- (Object) commands
Returns the value of attribute commands
12 13 14 |
# File 'lib/trooper/action.rb', line 12 def commands @commands end |
- (Object) config (readonly)
Returns the value of attribute config
11 12 13 |
# File 'lib/trooper/action.rb', line 11 def config @config end |
- (Object) description (readonly)
Returns the value of attribute description
11 12 13 |
# File 'lib/trooper/action.rb', line 11 def description @description end |
- (Object) name (readonly)
Returns the value of attribute name
11 12 13 |
# File 'lib/trooper/action.rb', line 11 def name @name end |
- (Object) options (readonly)
Returns the value of attribute options
11 12 13 |
# File 'lib/trooper/action.rb', line 11 def @options end |
Instance Method Details
- (Object) call(configuration) Also known as: execute
Public: Eval's the block passed on initialize.
configuration - The configuration object to be used for block eval.
Examples
@action.call(config_object) # => ['touch file']
Returns an array of commands(strings).
41 42 43 44 45 |
# File 'lib/trooper/action.rb', line 41 def call(configuration) @config = configuration eval_block(&block) commands end |
- (Boolean) ok?
Public: Validates the action object. (NOT WORKING)
Examples
@action.ok? # => true
Returns true.
71 72 73 |
# File 'lib/trooper/action.rb', line 71 def ok? true end |
- (Object) prerequisite_call(configuration)
Public: Modifies the commands list to include the prerequisite list checker .
configuration - The configuration object to be used for block eval.
Examples
@action.call(config_object) # => "..."
Returns a command String.
57 58 59 60 61 62 |
# File 'lib/trooper/action.rb', line 57 def prerequisite_call(configuration) original_commands = call configuration original_commands << "echo '#{self.name}' >> #{prerequisite_list}" original_commands << "echo '#{self.description}'" "touch #{prerequisite_list}; if grep -vz #{self.name} #{prerequisite_list}; then #{original_commands.join(' && ')}; else echo 'Already Done'; fi" end |
- (Object) run(command)
Public: Appends command(string) to commands(array).
command - A String to be added to the commands array.
Examples
@action.run 'touch file' # => 'touch file'
@action.run '' # => nil
Returns the command or nil.
99 100 101 |
# File 'lib/trooper/action.rb', line 99 def run(command) commands << command if command != '' end |
- (Object) type
Public: What type of action this is.
Examples
@action.type # => :action
@action.type # => :local_action
Returns a Symbol.
83 84 85 |
# File 'lib/trooper/action.rb', line 83 def type && [:local] ? :local_action : :action end |