Class: Trooper::Strategy
- Inherits:
-
Object
- Object
- Trooper::Strategy
- Defined in:
- lib/trooper/strategy.rb
Instance Attribute Summary (collapse)
-
- (Object) block
readonly
Returns the value of attribute block.
-
- (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) prereq_run_list
readonly
Returns the value of attribute prereq_run_list.
-
- (Object) run_list
readonly
Returns the value of attribute run_list.
Instance Method Summary (collapse)
-
- (Object) action(name, description = "No Description", &block)
Public: Add an Action to the Task list but scoped to this Strategy (Action Not available outside this object).
-
- (Object) actions(*action_names)
Public: Add actions to the run list.
-
- (Object) call(*strategy_names)
Public: Add other strategies actions to the run list.
-
- (Strategy) initialize(name, description, config = {}, &block)
constructor
Public: Initialize a new Strategy object.
-
- (Object) list(configuration = {})
Public: The Task List.
-
- (Object) method_missing(method_sym, *arguments, &block)
:nodoc:.
-
- (Boolean) ok?
Public: Validates the strategy object.
-
- (Object) prerequisites(*strategy_names)
Public: Add other strategies actions to the prerequisite run list.
Constructor Details
- (Strategy) initialize(name, description, config = {}, &block)
Public: Initialize a new Strategy object.
name - A Symbol of the strategy name description - A String of what this strategy will do. config - A Hash of config options expects a Trooper::Configuration object block - A block to be eval with the strategy object
Examples
Strategy.new :my_strategy, 'Does something cool' do
actions :my_action
end
Returns a Host object.
22 23 24 25 |
# File 'lib/trooper/strategy.rb', line 22 def initialize(name, description, config = {}, &block) @name, @description, @config = name, description, config @run_list, @prereq_run_list, @block = [], [], block end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
- (Object) method_missing(method_sym, *arguments, &block)
:nodoc:
136 137 138 |
# File 'lib/trooper/strategy.rb', line 136 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
6 7 8 |
# File 'lib/trooper/strategy.rb', line 6 def block @block end |
- (Object) config (readonly)
Returns the value of attribute config
6 7 8 |
# File 'lib/trooper/strategy.rb', line 6 def config @config end |
- (Object) description (readonly)
Returns the value of attribute description
6 7 8 |
# File 'lib/trooper/strategy.rb', line 6 def description @description end |
- (Object) name (readonly)
Returns the value of attribute name
6 7 8 |
# File 'lib/trooper/strategy.rb', line 6 def name @name end |
- (Object) prereq_run_list (readonly)
Returns the value of attribute prereq_run_list
6 7 8 |
# File 'lib/trooper/strategy.rb', line 6 def prereq_run_list @prereq_run_list end |
- (Object) run_list (readonly)
Returns the value of attribute run_list
6 7 8 |
# File 'lib/trooper/strategy.rb', line 6 def run_list @run_list end |
Instance Method Details
- (Object) action(name, description = "No Description", &block)
Public: Add an Action to the Task list but scoped to this Strategy (Action Not available outside this object).
name - The name of the action. description - A description of action to be used in the cli output. block - A block containing the tasks to run in this action.
Examples
@strategy.action(:my_action, 'Does great things') { run 'touch file' }
Returns an Action object.
112 113 114 115 116 117 118 119 120 |
# File 'lib/trooper/strategy.rb', line 112 def action(name, description = "No Description", &block) action_name = "#{self.name}_#{name}".to_sym action = Trooper::Action.new action_name, description, &block Arsenal.actions.add action actions action_name action end |
- (Object) actions(*action_names)
Public: Add actions to the run list.
action_names - A list of Action names.
Examples
@strategy.actions(:my_action) # => nil
Returns nil.
91 92 93 94 95 96 97 98 |
# File 'lib/trooper/strategy.rb', line 91 def actions(*action_names) [*action_names].each do |name| if Arsenal.actions[name] # strategy_name, type, name @run_list << [self.name, Arsenal.actions[name].type, name] end end end |
- (Object) call(*strategy_names)
Public: Add other strategies actions to the run list.
strategy_names - A list of other Strategy names.
Examples
@strategy.call(:my_other_strategy) # => nil
Returns nil.
47 48 49 50 51 52 53 54 55 56 |
# File 'lib/trooper/strategy.rb', line 47 def call(*strategy_names) [*strategy_names].each do |strategy_name| if Arsenal.strategies[strategy_name] Arsenal.strategies[strategy_name].list(config).each do |action| # strategy_name, type, name @run_list << action end end end end |
- (Object) list(configuration = {})
Public: The Task List.
configuration - A optional Trooper::Configuration object.
Examples
@strategy.list() # => [[:my_strategy, :action, :my_strategy_my_new_action]]
Returns and Array of Arrays.
131 132 133 134 |
# File 'lib/trooper/strategy.rb', line 131 def list(configuration = {}) build_list(configuration) if run_list == [] prereq_run_list + run_list end |
- (Boolean) ok?
Public: Validates the strategy object. (NOT WORKING)
Examples
@strategy.ok? # => true
Returns true.
34 35 36 |
# File 'lib/trooper/strategy.rb', line 34 def ok? true end |
- (Object) prerequisites(*strategy_names)
Public: Add other strategies actions to the prerequisite run list.
strategy_names - A list of other Strategy names.
Examples
@strategy.prerequisites(:my_other_strategy) # => nil
Returns nil.
67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/trooper/strategy.rb', line 67 def prerequisites(*strategy_names) if @prereq_run_list == [] @prereq_run_list = [[@name, :action, :prepare_prerequisite]] end [*strategy_names].each do |strategy_name| if Arsenal.strategies[strategy_name] Arsenal.strategies[strategy_name].list(config).each do |action| # strategy_name, type, name @prereq_run_list << [action[0], :prerequisite, action[2]] end end end end |