pulse-meter 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
1
3
|
module PulseMeter
|
2
4
|
module Mixins
|
3
5
|
# Mixin with dumping utilities
|
@@ -10,7 +12,7 @@ module PulseMeter
|
|
10
12
|
# @raise [DumpError] if dumping fails for any reason
|
11
13
|
def dump!
|
12
14
|
ensure_storability!
|
13
|
-
serialized_obj =
|
15
|
+
serialized_obj = self.to_yaml
|
14
16
|
redis.hset(DUMP_REDIS_KEY, self.name, serialized_obj)
|
15
17
|
rescue
|
16
18
|
raise DumpError, "object cannot be dumped"
|
@@ -36,7 +38,7 @@ module PulseMeter
|
|
36
38
|
# @raise [RestoreError] if object cannot be restored for any reason
|
37
39
|
def restore(name)
|
38
40
|
serialized_obj = PulseMeter.redis.hget(DUMP_REDIS_KEY, name)
|
39
|
-
|
41
|
+
YAML::load(serialized_obj)
|
40
42
|
rescue
|
41
43
|
raise RestoreError, "cannot restore #{name}"
|
42
44
|
end
|
data/lib/pulse-meter/version.rb
CHANGED
@@ -7,16 +7,6 @@ describe PulseMeter::Mixins::Dumper do
|
|
7
7
|
|
8
8
|
class Bad < Base; end
|
9
9
|
|
10
|
-
class Undumpable < Base
|
11
|
-
def name; :name; end
|
12
|
-
|
13
|
-
def redis; PulseMeter.redis; end
|
14
|
-
|
15
|
-
def initialize
|
16
|
-
@socket = Socket.new(:INET, :STREAM)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
10
|
class Good < Base
|
21
11
|
attr_accessor :foo
|
22
12
|
def name; foo.to_s; end
|
@@ -29,7 +19,6 @@ describe PulseMeter::Mixins::Dumper do
|
|
29
19
|
end
|
30
20
|
|
31
21
|
let(:bad_obj){ Bad.new }
|
32
|
-
let(:undumpable_obj){ Undumpable.new }
|
33
22
|
let(:good_obj){ Good.new(:foo) }
|
34
23
|
let(:another_good_obj){ Good.new(:bar) }
|
35
24
|
let(:redis){ PulseMeter.redis }
|
@@ -57,12 +46,6 @@ describe PulseMeter::Mixins::Dumper do
|
|
57
46
|
expect{ bad_obj.dump! }.to raise_exception(PulseMeter::DumpError)
|
58
47
|
end
|
59
48
|
end
|
60
|
-
|
61
|
-
context "when object cannot be dumped" do
|
62
|
-
it "should raise exception" do
|
63
|
-
expect {undumpable_obj.dump!}.to raise_exception(PulseMeter::DumpError)
|
64
|
-
end
|
65
|
-
end
|
66
49
|
end
|
67
50
|
|
68
51
|
context "when class follows dump contract" do
|
data/spec/spec_helper.rb
CHANGED
@@ -12,7 +12,6 @@ SimpleCov.start
|
|
12
12
|
|
13
13
|
require 'pulse-meter'
|
14
14
|
require 'pulse-meter/visualizer'
|
15
|
-
require 'test_helpers/matchers'
|
16
15
|
require 'rack/test'
|
17
16
|
|
18
17
|
|
@@ -24,6 +23,6 @@ RSpec.configure do |config|
|
|
24
23
|
config.before(:each) { PulseMeter.redis = MockRedis.new }
|
25
24
|
config.filter_run :focus => true
|
26
25
|
config.run_all_when_everything_filtered = true
|
27
|
-
config.include(
|
26
|
+
config.include(Matchers)
|
28
27
|
end
|
29
28
|
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Matchers
|
2
|
+
|
3
|
+
class GenerallyEqual
|
4
|
+
|
5
|
+
EPSILON = 0.0001
|
6
|
+
|
7
|
+
def initialize(expected)
|
8
|
+
@expected = expected
|
9
|
+
end
|
10
|
+
|
11
|
+
def matches?(actual)
|
12
|
+
@actual = actual
|
13
|
+
|
14
|
+
if @actual.kind_of?(Float) || @expected.kind_of?(Float)
|
15
|
+
(@expected - EPSILON .. @expected + EPSILON).include? @actual
|
16
|
+
else
|
17
|
+
@expected == @actual
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def failure_message_for_should
|
22
|
+
"expected #{@actual.inspect} to be generally equal to #{@expected.inspect}"
|
23
|
+
end
|
24
|
+
|
25
|
+
def failure_message_for_should_not
|
26
|
+
"expected #{@actual.inspect} not to be generally equal to #{@expected.inspect}"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def be_generally_equal(expected)
|
31
|
+
GenerallyEqual.new(expected)
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
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.0
|
4
|
+
version: 0.1.0
|
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-05-
|
13
|
+
date: 2012-05-27 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: gon-sinatra
|
@@ -342,7 +342,6 @@ files:
|
|
342
342
|
- lib/pulse-meter/visualize/views/main.haml
|
343
343
|
- lib/pulse-meter/visualize/widget.rb
|
344
344
|
- lib/pulse-meter/visualizer.rb
|
345
|
-
- lib/test_helpers/matchers.rb
|
346
345
|
- pulse-meter.gemspec
|
347
346
|
- spec/pulse_meter/mixins/dumper_spec.rb
|
348
347
|
- spec/pulse_meter/mixins/utils_spec.rb
|
@@ -372,6 +371,7 @@ files:
|
|
372
371
|
- spec/shared_examples/timeline_sensor.rb
|
373
372
|
- spec/shared_examples/timelined_subclass.rb
|
374
373
|
- spec/spec_helper.rb
|
374
|
+
- spec/support/matchers.rb
|
375
375
|
homepage: ''
|
376
376
|
licenses: []
|
377
377
|
post_install_message:
|
@@ -386,7 +386,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
386
386
|
version: '0'
|
387
387
|
segments:
|
388
388
|
- 0
|
389
|
-
hash:
|
389
|
+
hash: 4071351683887129800
|
390
390
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
391
391
|
none: false
|
392
392
|
requirements:
|
@@ -395,7 +395,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
395
395
|
version: '0'
|
396
396
|
segments:
|
397
397
|
- 0
|
398
|
-
hash:
|
398
|
+
hash: 4071351683887129800
|
399
399
|
requirements: []
|
400
400
|
rubyforge_project:
|
401
401
|
rubygems_version: 1.8.24
|
@@ -432,4 +432,5 @@ test_files:
|
|
432
432
|
- spec/shared_examples/timeline_sensor.rb
|
433
433
|
- spec/shared_examples/timelined_subclass.rb
|
434
434
|
- spec/spec_helper.rb
|
435
|
+
- spec/support/matchers.rb
|
435
436
|
has_rdoc:
|
@@ -1,36 +0,0 @@
|
|
1
|
-
module TestHelpers
|
2
|
-
module Matchers
|
3
|
-
|
4
|
-
class GenerallyEqual
|
5
|
-
|
6
|
-
EPSILON = 0.0001
|
7
|
-
|
8
|
-
def initialize(expected)
|
9
|
-
@expected = expected
|
10
|
-
end
|
11
|
-
|
12
|
-
def matches?(actual)
|
13
|
-
@actual = actual
|
14
|
-
|
15
|
-
if @actual.kind_of?(Float) || @expected.kind_of?(Float)
|
16
|
-
(@expected - EPSILON .. @expected + EPSILON).include? @actual
|
17
|
-
else
|
18
|
-
@expected == @actual
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
def failure_message_for_should
|
23
|
-
"expected #{@actual.inspect} to be generally equal to #{@expected.inspect}"
|
24
|
-
end
|
25
|
-
|
26
|
-
def failure_message_for_should_not
|
27
|
-
"expected #{@actual.inspect} not to be generally equal to #{@expected.inspect}"
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
def be_generally_equal(expected)
|
32
|
-
GenerallyEqual.new(expected)
|
33
|
-
end
|
34
|
-
|
35
|
-
end
|
36
|
-
end
|