Class: PulseMeter::Sensor::Base Abstract

Inherits:
Object
  • Object
show all
Includes:
Mixins::Dumper
Defined in:
lib/pulse-meter/sensor/base.rb

Overview

This class is abstract.

Subclass and override #event to implement sensor

Direct Known Subclasses

Counter, Indicator, Timeline

Constant Summary

Constants included from Mixins::Dumper

Mixins::Dumper::DUMP_REDIS_KEY

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Mixins::Dumper

included

Constructor Details

#initialize(name, options = {}) ⇒ Base

Initializes sensor and dumps it to redis

Parameters:

  • name (String)

    sensor name

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :annotation (String)

    Sensor annotation

Raises:



19
20
21
22
23
24
25
26
27
# File 'lib/pulse-meter/sensor/base.rb', line 19

def initialize(name, options={})
  @name = name.to_s
  if options[:annotation]
    annotate(options[:annotation])
  end
  raise BadSensorName, @name unless @name =~ /\A\w+\z/
  raise RedisNotInitialized unless PulseMeter.redis
  dump!
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



12
13
14
# File 'lib/pulse-meter/sensor/base.rb', line 12

def name
  @name
end

#redisObject

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

Parameters:

  • description (String)

    Sensor annotation



36
37
38
# File 'lib/pulse-meter/sensor/base.rb', line 36

def annotate(description)
  redis.set(desc_key, description)
end

#annotationString

Retrieves annotation from Redis

Returns:

  • (String)

    Sensor annotation



42
43
44
# File 'lib/pulse-meter/sensor/base.rb', line 42

def annotation
  redis.get(desc_key)
end

#cleanupObject

Cleans up all sensor metadata in Redis



47
48
49
50
# File 'lib/pulse-meter/sensor/base.rb', line 47

def cleanup
  redis.del(desc_key)
  cleanup_dump
end

#event(value) ⇒ Object

This method is abstract.

Processes event

Parameters:

  • value (Object)

    value produced by some kind of event



54
55
56
# File 'lib/pulse-meter/sensor/base.rb', line 54

def event(value)
  # do nothing here
end