Class: PulseMeter::Sensor::Base Abstract
- Inherits:
-
Object
- Object
- PulseMeter::Sensor::Base
- Includes:
- Mixins::Dumper
- Defined in:
- lib/pulse_meter/sensor/base.rb
Overview
This class is abstract.
Subclass and override #event to implement sensor
Constant Summary
Constants included from Mixins::Dumper
Mixins::Dumper::DUMP_REDIS_KEY
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#redis ⇒ Object
Returns Redis instance.
Instance Method Summary collapse
-
#annotate(description) ⇒ Object
Saves annotation to Redis.
-
#annotation ⇒ String
Retrieves annotation from Redis.
-
#cleanup ⇒ Object
Cleans up all sensor metadata in Redis.
- #command_aggregator ⇒ Object
-
#event(value) ⇒ Object
Processes event.
-
#initialize(name, options = {}) ⇒ Base
constructor
Initializes sensor and dumps it to redis.
Methods included from Mixins::Dumper
Constructor Details
#initialize(name, options = {}) ⇒ Base
Initializes sensor and dumps it to redis
19 20 21 22 23 24 25 26 27 |
# File 'lib/pulse_meter/sensor/base.rb', line 19 def initialize(name, ={}) @name = name.to_s if [:annotation] annotate([:annotation]) end raise BadSensorName, @name unless @name =~ /\A[\w@]+\z/ raise RedisNotInitialized unless PulseMeter.redis dump! end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
12 13 14 |
# File 'lib/pulse_meter/sensor/base.rb', line 12 def name @name end |
#redis ⇒ Object
Returns Redis instance
9 10 11 |
# File 'lib/pulse_meter/sensor/base.rb', line 9 def redis @redis end |
Instance Method Details
#annotate(description) ⇒ Object
Saves annotation to Redis
40 41 42 |
# File 'lib/pulse_meter/sensor/base.rb', line 40 def annotate(description) redis.set(desc_key, description) end |
#annotation ⇒ String
Retrieves annotation from Redis
46 47 48 |
# File 'lib/pulse_meter/sensor/base.rb', line 46 def annotation redis.get(desc_key) end |
#cleanup ⇒ Object
Cleans up all sensor metadata in Redis
51 52 53 54 |
# File 'lib/pulse_meter/sensor/base.rb', line 51 def cleanup redis.del(desc_key) cleanup_dump end |
#command_aggregator ⇒ Object
34 35 36 |
# File 'lib/pulse_meter/sensor/base.rb', line 34 def command_aggregator PulseMeter.command_aggregator end |
#event(value) ⇒ Object
Processes event
58 59 60 61 62 63 |
# File 'lib/pulse_meter/sensor/base.rb', line 58 def event(value) process_event(value) true rescue StandardError => e false end |