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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 92900fd04f309c9956669bff7d8f5d2e4ad8ac37
4
- data.tar.gz: 2d5000f4ebf8f5201f93da339118eb8abfc19c02
3
+ metadata.gz: 0f72ce9168131992209858aa64f9873753595c91
4
+ data.tar.gz: 39d8ca4255dfb87a53d773b1785bd7540e3692ff
5
5
  SHA512:
6
- metadata.gz: 2774e65b99b718e2c1384df139ccb354a2fb435f81da3b80a416dd978192dc12ce457cf7149be2b4c92d589400935875d6bfc7fd4b98ea416ef60e226a8a202a
7
- data.tar.gz: bfbde7e732bca79edc7d07538c27ac31993897de7740d237a098f768dabe3174be2cd1e23c29564b2c382792bb3de4709c83886242c35cc4835380917bbcb975
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.5...HEAD
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
@@ -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>]
@@ -1,3 +1,3 @@
1
1
  module FakeConsul
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
@@ -3,6 +3,8 @@ require_relative '../spec_helper'
3
3
  describe FakeConsul::Server do
4
4
  subject { FakeConsul::Server.new }
5
5
 
6
+ before { subject.clear }
7
+
6
8
  describe '#put' do
7
9
  it 'stores key into Hash' do
8
10
  subject.put('foo', 'bar')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fake_consul
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Saimon Moore