Module: Hallmonitor::Monitored
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
-
#emit(event = nil) ⇒ Object
Emits an event: either self or an event if one is passed in, or constructs a base event from the passed in param If the parameter is a #Hallmonitor::Event, it will be emitted as is.
-
#watch(name) ⇒ Object
Executes and times a block of code and emits a Hallmonitor::TimedEvent.
Class Method Details
.included(base) ⇒ Object
40 41 42 |
# File 'lib/hallmonitor/monitored.rb', line 40 def self.included(base) base.extend(ClassMethods) end |
Instance Method Details
#emit(event = nil) ⇒ Object
Emits an event: either self or an event if one is passed in, or constructs a base event from the passed in param If the parameter is a #Hallmonitor::Event, it will be emitted as is. Otherwise, a new Hallmonitor::Event will be created with the parameter and emitted.
49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/hallmonitor/monitored.rb', line 49 def emit(event = nil) to_emit = self; if(!event.nil?) to_emit = event.kind_of?(Hallmonitor::Event) ? event : Hallmonitor::Event.new(event) end # If we were given a block, then we want to execute that if block_given? yield(to_emit) end Outputter.output(to_emit) end |
#watch(name) ⇒ Object
Executes and times a block of code and emits a Hallmonitor::TimedEvent
65 66 67 68 69 70 71 72 |
# File 'lib/hallmonitor/monitored.rb', line 65 def watch(name) event = Hallmonitor::TimedEvent.new(name) event.start = Time.now retval = yield(event) event.stop = Time.now emit(event) retval end |