Class: PoolParty::Monitor
Instance Attribute Summary collapse
-
#monitor_block ⇒ Object
readonly
Returns the value of attribute monitor_block.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
-
#initialize(monitor_name, &block) ⇒ Monitor
constructor
A new instance of Monitor.
-
#run(val) ⇒ Object
Run the block given with the monitor with the given values on run.
Constructor Details
#initialize(monitor_name, &block) ⇒ Monitor
Returns a new instance of Monitor.
20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/poolparty/monitor.rb', line 20 def initialize(monitor_name, &block) msg =<<-EOE You must pass a block with your monitor Example: monitor :cpu do |c| vote_for(:expand) if c > 0.8 configure if c < 0.1 end EOE raise PoolPartyError.create("MonitorDefinitionError", msg) unless block @name = monitor_name @monitor_block = block end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *a, &block) ⇒ Object (private)
We don’t want the methods actually executing since we are executing the methods in a cloud, we just want to store the output values of the methods, so we’ll store them in a hash with the method as the key and the value of the method as the value in an array
50 51 52 53 |
# File 'lib/poolparty/monitor.rb', line 50 def method_missing(meth,*a,&block) (methods[meth] ||= []) << a methods[meth].flatten! end |
Instance Attribute Details
#monitor_block ⇒ Object (readonly)
Returns the value of attribute monitor_block.
18 19 20 |
# File 'lib/poolparty/monitor.rb', line 18 def monitor_block @monitor_block end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
18 19 20 |
# File 'lib/poolparty/monitor.rb', line 18 def name @name end |
Instance Method Details
#run(val) ⇒ Object
Run the block given with the monitor with the given values on run. Clear the methods hash out so they don’t conflict with the previous values retrieved and return the methods available.
38 39 40 41 42 |
# File 'lib/poolparty/monitor.rb', line 38 def run(val) @methods = nil instance_exec val, &monitor_block methods end |