fake_consul 0.0.5 → 0.0.6
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -1
- data/lib/fake_consul/server.rb +39 -0
- data/lib/fake_consul/version.rb +1 -1
- data/spec/fake_consul/server_spec.rb +2 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0f72ce9168131992209858aa64f9873753595c91
|
4
|
+
data.tar.gz: 39d8ca4255dfb87a53d773b1785bd7540e3692ff
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a6ef6bf4018bde781c2a12d2a8b8d7bc1aca00031c1667ef7f1dc72c6762e209d52c240659bb613de64eeb8d791b39b1172aef35aa443f25f45a9b825d1cd4ef
|
7
|
+
data.tar.gz: d52766d50bd428cd9dda12ec0522b4b7458209349a572a980ed285be78c41d68313f69352dd2a947859942eb3fad0f4378a9a05426e157ce41a4736b0b74ac42
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,9 @@
|
|
2
2
|
All notable changes to this project will be documented in this file.
|
3
3
|
This project adheres to [Semantic Versioning](http://semver.org/).
|
4
4
|
|
5
|
+
## [v0.0.6] - 2015-11-27
|
6
|
+
- Add persistance to disk
|
7
|
+
|
5
8
|
## [v0.0.5] - 2015-11-27
|
6
9
|
- Add missing require
|
7
10
|
|
@@ -19,7 +22,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
|
19
22
|
- Adds simple consul client that fakes the consul server and provides state in an in-memory Hash.
|
20
23
|
- Client API conforms to that of [Diplomat::Kv](http://www.rubydoc.info/github/WeAreFarmGeek/diplomat/Diplomat/Kv) (See source here: [Diplomat](https://github.com/WeAreFarmGeek/diplomat) )
|
21
24
|
|
22
|
-
[unreleased]: https://github.com/redbooth/fake_consul/compare/v0.0.
|
25
|
+
[unreleased]: https://github.com/redbooth/fake_consul/compare/v0.0.6...HEAD
|
26
|
+
[v0.0.6]: https://github.com/redbooth/fake_consul/tree/v0.0.6
|
23
27
|
[v0.0.5]: https://github.com/redbooth/fake_consul/tree/v0.0.5
|
24
28
|
[v0.0.4]: https://github.com/redbooth/fake_consul/tree/v0.0.4
|
25
29
|
[v0.0.3]: https://github.com/redbooth/fake_consul/tree/v0.0.3
|
data/lib/fake_consul/server.rb
CHANGED
@@ -1,8 +1,13 @@
|
|
1
1
|
require "active_support/hash_with_indifferent_access"
|
2
|
+
require "tmpdir"
|
2
3
|
|
3
4
|
module FakeConsul
|
4
5
|
class Server < HashWithIndifferentAccess
|
5
6
|
|
7
|
+
def initialize
|
8
|
+
restore!
|
9
|
+
end
|
10
|
+
|
6
11
|
# Fake get
|
7
12
|
#
|
8
13
|
# Performs no http requests but stores data in local hash
|
@@ -33,11 +38,45 @@ module FakeConsul
|
|
33
38
|
def put(key, value, options = nil)
|
34
39
|
self[key] = value
|
35
40
|
compact
|
41
|
+
persist!
|
36
42
|
true
|
37
43
|
end
|
38
44
|
|
45
|
+
# Clear current data
|
46
|
+
# and delete backing marshalling file
|
47
|
+
def clear
|
48
|
+
super
|
49
|
+
return unless File.exist?(db_file)
|
50
|
+
File.delete(db_file)
|
51
|
+
end
|
52
|
+
|
39
53
|
private
|
40
54
|
|
55
|
+
# Persist current data to marshalled file
|
56
|
+
def persist!
|
57
|
+
File.open(db_file, 'w+') do |f|
|
58
|
+
Marshal.dump(self, f)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
# Restore hash from marshalled data
|
63
|
+
def restore!
|
64
|
+
return unless File.exist?(db_file)
|
65
|
+
|
66
|
+
File.open(db_file) do |f|
|
67
|
+
restored_data = Marshal.load(f)
|
68
|
+
self.clear
|
69
|
+
self.merge!(restored_data)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
# Path to marshalled file
|
74
|
+
#
|
75
|
+
# @return [String]
|
76
|
+
def db_file
|
77
|
+
"#{Dir.tmpdir}#{File::SEPARATOR}.fake_consul.m"
|
78
|
+
end
|
79
|
+
|
41
80
|
# Returns the keys in the following format:
|
42
81
|
# [{key: `key`, value: 'bar'}]
|
43
82
|
# @return [Array<Hash>]
|
data/lib/fake_consul/version.rb
CHANGED