Class: RightScale::CloudApi::Routine
- Defined in:
- lib/base/routines/routine.rb
Overview
This is a parent class for all the other routines.
The routine is a very simple object that does a simple task in the API call processing stack and exits. In most cases a single routine knows nothing about any other routines. It just takes incoming params from @data hash, processes it and stores back to the @adata attribute.
Direct Known Subclasses
CacheValidator, ConnectionProxy, RequestAnalyzer, RequestGenerator, RequestInitializer, ResponseAnalyzer, ResponseParser, ResultWrapper, RetryManager
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
Instance Method Summary collapse
-
#cloud_api_logger ⇒ CloudApiLogger
Current logger.
-
#execute(data) ⇒ Object
Initialize and process the routine.
-
#invoke_callback_method(proc, *args) ⇒ Object
A helper method for invoking callbacks.
-
#options ⇒ Hash
Current options.
-
#process ⇒ Object
Main entry point.
-
#reset(data = nil) ⇒ Object
Initializes the @data attribute.
-
#with_timer(description = 'Timer', log_key = :timer, &block) ⇒ Object
The method takes a block of code and logs how much time the given block took to execute.
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
34 35 36 |
# File 'lib/base/routines/routine.rb', line 34 def data @data end |
Instance Method Details
#cloud_api_logger ⇒ CloudApiLogger
Current logger.
67 68 69 |
# File 'lib/base/routines/routine.rb', line 67 def cloud_api_logger [:cloud_api_logger] end |
#execute(data) ⇒ Object
Initialize and process the routine. Is usially called from unit tests.
50 51 52 53 |
# File 'lib/base/routines/routine.rb', line 50 def execute(data) reset(data) process end |
#invoke_callback_method(proc, *args) ⇒ Object
A helper method for invoking callbacks.
The method checks if the given Proc exists and invokes it with the given set of arguments. In the case when proc==nil the method does nothing.
92 93 94 |
# File 'lib/base/routines/routine.rb', line 92 def invoke_callback_method(proc, *args) # :nodoc: proc.call(*args) if proc.is_a?(Proc) end |
#options ⇒ Hash
Current options.
59 60 61 |
# File 'lib/base/routines/routine.rb', line 59 def @data[:options] end |
#process ⇒ Object
Main entry point. The method must be overriden by sub-classes.
45 46 47 |
# File 'lib/base/routines/routine.rb', line 45 def process raise Error::new("This method should be implemented by a subclass") end |
#reset(data = nil) ⇒ Object
Initializes the @data attribute. Is called before process method.
40 41 42 |
# File 'lib/base/routines/routine.rb', line 40 def reset(data=nil) @data = data end |
#with_timer(description = 'Timer', log_key = :timer, &block) ⇒ Object
The method takes a block of code and logs how much time the given block took to execute.
76 77 78 79 80 81 82 |
# File 'lib/base/routines/routine.rb', line 76 def with_timer(description = 'Timer', log_key = :timer, &block) cloud_api_logger.log("#{description} started...",:timer) start = Time::now result = block.call cloud_api_logger.log("#{description} completed (#{'%.6f' % (Time::now - start)} sec)", log_key) result end |