ruby_doozer 0.3.0 → 0.4.0

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: ef156e41c4d70417b9ccb4128c22b817c926c474
4
- data.tar.gz: c8c054bea13c4933368e12838526de1febe4e37a
3
+ metadata.gz: b15a0cb9ca75e17c5abe248f29b83f418570240b
4
+ data.tar.gz: 70fa3e7ccf86e679789a9f7858d80e90c5fada89
5
5
  SHA512:
6
- metadata.gz: 9483ea907342682619bb3e44a5bffa9c63b0f9519fedc9ced96b7e4b579fe07c2e6ab73f259a6711db5ad1f9f0b130f8d84187336523ac8660030121f57d81ef
7
- data.tar.gz: 8c5c70714dff4fe12c1cb7fda7573bcb37cb73f927f388460a6e0772d66d3e07778ea218d4d730b6c89af09255b7404e125c890a235eee3550fdb9b0cceca1b0
6
+ metadata.gz: b71b533217dfc507366609a9a2dcf16fd0bd9451bc26b9fd07c22594e5e044e76a1b38a7ef105ddbeba08b08092fb0b95e7e2636f29b292342ed88c827055c5e
7
+ data.tar.gz: 86ed713d400eb0980ceb7c6d0da3171e9b84432d06c51eedc3049499b033d9f987d2dc537982f4840b7bb51bb3c725f4a243a91f41f1ca2c311ff6349902d647
@@ -29,14 +29,14 @@ module RubyDoozer
29
29
  #
30
30
  def initialize(params)
31
31
  super
32
- @registry = ThreadSafe::Hash.new
32
+ @cache = ThreadSafe::Hash.new
33
33
 
34
34
  path = "#{@root_path}/**"
35
35
  doozer_pool.with_connection do |doozer|
36
36
  @current_revision = doozer.current_revision
37
37
  # Fetch all the configuration information from Doozer and set the internal copy
38
38
  doozer.walk(path, @current_revision).each do |node|
39
- @registry[relative_path(node.path)] = node.value
39
+ set_cached_value(relative_path(node.path), node.value)
40
40
  end
41
41
  end
42
42
 
@@ -46,7 +46,7 @@ module RubyDoozer
46
46
 
47
47
  # Retrieve the latest value from a specific path from the registry
48
48
  def [](path)
49
- @registry[path]
49
+ @cache[path]
50
50
  end
51
51
 
52
52
  # Iterate over every key, value pair in the registry at the root_path
@@ -56,17 +56,17 @@ module RubyDoozer
56
56
  def each_pair(&block)
57
57
  # Have to duplicate the registry otherwise changes to the registry will
58
58
  # interfere with the iterator
59
- @registry.dup.each_pair(&block)
59
+ @cache.dup.each_pair(&block)
60
60
  end
61
61
 
62
62
  # Returns [Array<String>] all paths in the registry
63
63
  def paths
64
- @registry.keys
64
+ @cache.keys
65
65
  end
66
66
 
67
67
  # Returns a copy of the registry as a Hash
68
68
  def to_h
69
- @registry.dup
69
+ @cache.dup
70
70
  end
71
71
 
72
72
  # When an entry is created the block will be called
@@ -96,12 +96,29 @@ module RubyDoozer
96
96
  ############################
97
97
  protected
98
98
 
99
+ # Sets the internal value for a specific key
100
+ # Called on startup to fill the internal registry and then every time a value
101
+ # changes in doozer
102
+ # This method can be replaced by derived Registries to change the format of
103
+ # the registry
104
+ def set_cached_value(doozer_path, value)
105
+ @cache[doozer_path] = value
106
+ end
107
+
108
+ # Returns the internal value for a specific key
109
+ # Called every time a value changes in doozer
110
+ # This method can be replaced by derived Registries to change the format of
111
+ # the registry
112
+ def get_cached_value(doozer_path)
113
+ @cache[doozer_path]
114
+ end
115
+
99
116
  # The path has been added or updated in the registry
100
117
  def changed(path, value)
101
- previous_value = @registry[path]
118
+ previous_value = get_cached_value(path)
102
119
 
103
120
  # Update in memory copy
104
- @registry[path] = value
121
+ set_cached_value(path, value)
105
122
 
106
123
  # It is an update if we already have a value
107
124
  if previous_value
@@ -9,6 +9,11 @@ module RubyDoozer
9
9
  include SemanticLogger::Loggable
10
10
 
11
11
  # Create a resilient client connection to a Doozer server
12
+ #
13
+ # Since Doozer does not support '_' and it is very prevalent in Ruby, all
14
+ # '_' passed in the path will be converted to '-' when calling doozer.
15
+ # All paths in doozer that contain '-' on the way back from doozer will be
16
+ # converted to '_'
12
17
  def initialize(params={})
13
18
  # User configurable options
14
19
  params[:read_timeout] ||= 5
@@ -187,6 +192,8 @@ module RubyDoozer
187
192
 
188
193
  # Send the protobuf Request to Doozer
189
194
  def send(request)
195
+ # Translate path so that underscores are converted to minuses
196
+ request.path.gsub!('_', '-')
190
197
  request.tag = 0
191
198
  data = request.serialize_to_string
192
199
  # An additional header is added to the request indicating the size of the request
@@ -199,7 +206,10 @@ module RubyDoozer
199
206
  # First strip the additional header indicating the size of the subsequent response
200
207
  head = @socket.read(4,nil,timeout)
201
208
  length = head.unpack("N")[0]
202
- Response.new.parse_from_string(@socket.read(length))
209
+ response = Response.new.parse_from_string(@socket.read(length))
210
+ # Translate returned path so that minuses are converted to underscores
211
+ response.path.gsub!('_', '-')
212
+ response
203
213
  end
204
214
 
205
215
  end
@@ -1,3 +1,3 @@
1
1
  module RubyDoozer #:nodoc
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.0"
3
3
  end
data/test/client_test.rb CHANGED
@@ -49,17 +49,20 @@ class ClientTest < Test::Unit::TestCase
49
49
  assert @client.current_revision >= 0
50
50
  end
51
51
 
52
- should "successfully set and get data" do
53
- new_revision = @client.set('/test/foo', 'value')
54
- result = @client.get('/test/foo')
55
- assert_equal 'value', result.value
56
- assert_equal new_revision, result.rev
57
- end
52
+ ['/test/foo', '/test/with_underscores'].each do |path|
53
+
54
+ should "successfully set and get data in #{path}" do
55
+ new_revision = @client.set(path, 'value')
56
+ result = @client.get(path)
57
+ assert_equal 'value', result.value
58
+ assert_equal new_revision, result.rev
59
+ end
58
60
 
59
- should "successfully set and get data using array operators" do
60
- @client['/test/foo'] = 'value2'
61
- result = @client['/test/foo']
62
- assert_equal 'value2', result
61
+ should "successfully set and get data using array operators in #{path}" do
62
+ @client[path] = 'value2'
63
+ result = @client[path]
64
+ assert_equal 'value2', result
65
+ end
63
66
  end
64
67
 
65
68
  should "fetch directories in a path" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_doozer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Reid Morrison
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-03-29 00:00:00.000000000 Z
11
+ date: 2013-04-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: semantic_logger