Class: ChefApply::Action::Base
- Inherits:
- 
      Object
      
        - Object
- ChefApply::Action::Base
 
- Defined in:
- lib/chef_apply/action/base.rb
Overview
Derive new Actions from Action::Base “target_host” is a TargetHost that the action is being applied to. May be nil
if the action does not require a target.
“config” is hash containing any options that your command may need
Implement perform_action to perform whatever action your class is intended to do. Run time will be captured via telemetry and categorized under “:action” with the unqualified class name of your Action.
Direct Known Subclasses
ConvergeTarget, GenerateLocalPolicy, GenerateTempCookbook, InstallChef
Instance Attribute Summary collapse
- 
  
    
      #config  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    Returns the value of attribute config. 
- 
  
    
      #target_host  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    Returns the value of attribute target_host. 
Instance Method Summary collapse
- 
  
    
      #initialize(config = {})  ⇒ Base 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    A new instance of Base. 
- #name ⇒ Object
- #notify(action, *args) ⇒ Object
- #perform_action ⇒ Object
- #run(&block) ⇒ Object
Constructor Details
#initialize(config = {}) ⇒ Base
Returns a new instance of Base.
| 34 35 36 37 38 39 | # File 'lib/chef_apply/action/base.rb', line 34 def initialize(config = {}) c = config.dup @target_host = c.delete :target_host # Remaining options are for child classes to make use of. @config = c end | 
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
| 32 33 34 | # File 'lib/chef_apply/action/base.rb', line 32 def config @config end | 
#target_host ⇒ Object (readonly)
Returns the value of attribute target_host.
| 32 33 34 | # File 'lib/chef_apply/action/base.rb', line 32 def target_host @target_host end | 
Instance Method Details
#name ⇒ Object
| 58 59 60 | # File 'lib/chef_apply/action/base.rb', line 58 def name self.class.name.split("::").last end | 
#notify(action, *args) ⇒ Object
| 66 67 68 69 70 71 | # File 'lib/chef_apply/action/base.rb', line 66 def notify(action, *args) return if @notification_handler.nil? ChefApply::Log.debug("[#{self.class.name}] Action: #{action}, Action Data: #{args}") @notification_handler.call(action, args) if @notification_handler end | 
#perform_action ⇒ Object
| 62 63 64 | # File 'lib/chef_apply/action/base.rb', line 62 def perform_action raise NotImplemented end | 
#run(&block) ⇒ Object
| 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | # File 'lib/chef_apply/action/base.rb', line 41 def run(&block) @notification_handler = block Telemeter.timed_action_capture(self) do perform_action rescue StandardError => e # Give the caller a chance to clean up - if an exception is # raised it'll otherwise get routed through the executing thread, # providing no means of feedback for the caller's current task. notify(:error, e) @error = e end # Raise outside the block to ensure that the telemetry capture completes raise @error unless @error.nil? end |