pulse-meter 0.1.8 → 0.1.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,12 +1,12 @@
|
|
1
1
|
$: << File.join(File.absolute_path(__FILE__), '..', 'lib')
|
2
2
|
|
3
3
|
require "pulse-meter"
|
4
|
-
|
4
|
+
|
5
5
|
PulseMeter.redis = Redis.new
|
6
6
|
|
7
7
|
cfg = PulseMeter::Sensor::Configuration.new(
|
8
8
|
lama_count: {
|
9
|
-
|
9
|
+
sensor_type:'timelined/counter',
|
10
10
|
args: {
|
11
11
|
annotation: 'Lama Count',
|
12
12
|
interval: 10,
|
@@ -15,7 +15,7 @@ cfg = PulseMeter::Sensor::Configuration.new(
|
|
15
15
|
},
|
16
16
|
|
17
17
|
lama_average_age: {
|
18
|
-
|
18
|
+
sensor_type:'timelined/average',
|
19
19
|
args: {
|
20
20
|
annotation: 'Lama Average Age',
|
21
21
|
interval: 20,
|
@@ -24,7 +24,7 @@ cfg = PulseMeter::Sensor::Configuration.new(
|
|
24
24
|
},
|
25
25
|
|
26
26
|
rhino_count: {
|
27
|
-
|
27
|
+
sensor_type:'timelined/counter',
|
28
28
|
args: {
|
29
29
|
annotation: 'Rhino Count',
|
30
30
|
interval: 10,
|
@@ -33,7 +33,7 @@ cfg = PulseMeter::Sensor::Configuration.new(
|
|
33
33
|
},
|
34
34
|
|
35
35
|
goose_count: {
|
36
|
-
|
36
|
+
sensor_type:'timelined/hashed_counter',
|
37
37
|
args: {
|
38
38
|
annotation: 'Goose Count',
|
39
39
|
interval: 10,
|
@@ -42,7 +42,7 @@ cfg = PulseMeter::Sensor::Configuration.new(
|
|
42
42
|
},
|
43
43
|
|
44
44
|
rhino_average_age: {
|
45
|
-
|
45
|
+
sensor_type:'timelined/average',
|
46
46
|
args: {
|
47
47
|
annotation: 'Rhino average age',
|
48
48
|
interval: 20,
|
@@ -11,8 +11,8 @@ module PulseMeter
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def add_sensor(name, opts)
|
14
|
-
|
15
|
-
klass_s = sensor_class(
|
14
|
+
sensor_type = opts.respond_to?(:sensor_type) ? opts.sensor_type : opts[:sensor_type]
|
15
|
+
klass_s = sensor_class(sensor_type)
|
16
16
|
klass = constantize(klass_s)
|
17
17
|
raise ArgumentError, "#{klass_s} is not a valid class for a sensor" unless klass
|
18
18
|
args = (opts.respond_to?(:args) ? opts.args : opts[:args]) || {}
|
@@ -34,8 +34,8 @@ module PulseMeter
|
|
34
34
|
|
35
35
|
protected
|
36
36
|
|
37
|
-
def sensor_class(
|
38
|
-
entries =
|
37
|
+
def sensor_class(sensor_type)
|
38
|
+
entries = sensor_type.to_s.split('/').map do |entry|
|
39
39
|
entry.split('_').map(&:capitalize).join
|
40
40
|
end
|
41
41
|
entries.unshift('PulseMeter::Sensor').join('::')
|
data/lib/pulse-meter/version.rb
CHANGED
@@ -6,34 +6,34 @@ describe PulseMeter::Sensor::Configuration do
|
|
6
6
|
|
7
7
|
it "should create sensor available under passed name" do
|
8
8
|
cfg.sensor(:foo).should be_nil
|
9
|
-
cfg.add_sensor(:foo,
|
9
|
+
cfg.add_sensor(:foo, sensor_type: 'counter')
|
10
10
|
cfg.sensor(:foo).should_not be_nil
|
11
11
|
end
|
12
12
|
|
13
13
|
it "should event shortcut for the sensor" do
|
14
|
-
cfg.add_sensor(:foo,
|
14
|
+
cfg.add_sensor(:foo, sensor_type: 'counter')
|
15
15
|
sensor = cfg.sensor(:foo)
|
16
16
|
sensor.should_receive(:event).with(321)
|
17
17
|
cfg.foo(321)
|
18
18
|
end
|
19
19
|
|
20
20
|
it "should create sensor with correct type" do
|
21
|
-
cfg.add_sensor(:foo,
|
21
|
+
cfg.add_sensor(:foo, sensor_type: 'counter')
|
22
22
|
cfg.sensor(:foo).should be_kind_of(PulseMeter::Sensor::Counter)
|
23
23
|
end
|
24
24
|
|
25
25
|
it "should raise exception if sensor type is bad" do
|
26
|
-
expect{ cfg.add_sensor(:foo,
|
26
|
+
expect{ cfg.add_sensor(:foo, sensor_type: 'baaaar') }.to raise_exception(ArgumentError)
|
27
27
|
end
|
28
28
|
|
29
29
|
it "should pass args to created sensor" do
|
30
|
-
cfg.add_sensor(:foo,
|
30
|
+
cfg.add_sensor(:foo, sensor_type: 'counter', args: {annotation: "My Foo Counter"} )
|
31
31
|
cfg.sensor(:foo).annotation.should == "My Foo Counter"
|
32
32
|
end
|
33
33
|
|
34
34
|
it "should accept hashie-objects" do
|
35
35
|
class Dummy
|
36
|
-
def
|
36
|
+
def sensor_type
|
37
37
|
'counter'
|
38
38
|
end
|
39
39
|
def args
|
@@ -52,10 +52,10 @@ describe PulseMeter::Sensor::Configuration do
|
|
52
52
|
it "should add passed sensor setting hash using keys as names" do
|
53
53
|
opts = {
|
54
54
|
cnt: {
|
55
|
-
|
55
|
+
sensor_type: 'counter'
|
56
56
|
},
|
57
57
|
ind: {
|
58
|
-
|
58
|
+
sensor_type: 'indicator'
|
59
59
|
}
|
60
60
|
}
|
61
61
|
cfg1 = described_class.new(opts)
|
@@ -69,7 +69,7 @@ describe PulseMeter::Sensor::Configuration do
|
|
69
69
|
it "should give access to added sensors" do
|
70
70
|
opts = {
|
71
71
|
cnt: {
|
72
|
-
|
72
|
+
sensor_type: 'counter',
|
73
73
|
args: {
|
74
74
|
annotation: "MySensor"
|
75
75
|
}
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pulse-meter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.9
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-06-
|
13
|
+
date: 2012-06-06 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: gon-sinatra
|