moneta 1.1.1 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (103) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +176 -0
  3. data/.travis.yml +57 -23
  4. data/CHANGES +12 -0
  5. data/Gemfile +89 -64
  6. data/README.md +40 -14
  7. data/feature_matrix.yaml +1 -0
  8. data/lib/action_dispatch/middleware/session/moneta_store.rb +1 -0
  9. data/lib/active_support/cache/moneta_store.rb +5 -5
  10. data/lib/moneta.rb +9 -1
  11. data/lib/moneta/adapters/activerecord.rb +35 -19
  12. data/lib/moneta/adapters/activesupportcache.rb +3 -7
  13. data/lib/moneta/adapters/cassandra.rb +24 -16
  14. data/lib/moneta/adapters/client.rb +13 -9
  15. data/lib/moneta/adapters/couch.rb +220 -80
  16. data/lib/moneta/adapters/datamapper.rb +1 -0
  17. data/lib/moneta/adapters/file.rb +9 -6
  18. data/lib/moneta/adapters/hbase.rb +1 -1
  19. data/lib/moneta/adapters/kyotocabinet.rb +8 -7
  20. data/lib/moneta/adapters/leveldb.rb +1 -1
  21. data/lib/moneta/adapters/lmdb.rb +3 -4
  22. data/lib/moneta/adapters/lruhash.rb +29 -62
  23. data/lib/moneta/adapters/memcached.rb +1 -0
  24. data/lib/moneta/adapters/memcached/dalli.rb +1 -1
  25. data/lib/moneta/adapters/memcached/native.rb +10 -8
  26. data/lib/moneta/adapters/mongo.rb +1 -0
  27. data/lib/moneta/adapters/mongo/base.rb +3 -3
  28. data/lib/moneta/adapters/mongo/moped.rb +12 -13
  29. data/lib/moneta/adapters/mongo/official.rb +7 -8
  30. data/lib/moneta/adapters/null.rb +1 -2
  31. data/lib/moneta/adapters/pstore.rb +3 -2
  32. data/lib/moneta/adapters/redis.rb +3 -3
  33. data/lib/moneta/adapters/restclient.rb +12 -3
  34. data/lib/moneta/adapters/riak.rb +2 -2
  35. data/lib/moneta/adapters/sequel.rb +112 -119
  36. data/lib/moneta/adapters/sqlite.rb +3 -3
  37. data/lib/moneta/adapters/tokyotyrant.rb +1 -1
  38. data/lib/moneta/builder.rb +0 -1
  39. data/lib/moneta/enumerable.rb +38 -0
  40. data/lib/moneta/expires.rb +12 -12
  41. data/lib/moneta/fallback.rb +84 -0
  42. data/lib/moneta/lock.rb +1 -1
  43. data/lib/moneta/logger.rb +2 -2
  44. data/lib/moneta/mixins.rb +12 -10
  45. data/lib/moneta/optionmerger.rb +0 -1
  46. data/lib/moneta/pool.rb +301 -31
  47. data/lib/moneta/proxy.rb +2 -2
  48. data/lib/moneta/server.rb +9 -12
  49. data/lib/moneta/shared.rb +1 -1
  50. data/lib/moneta/stack.rb +6 -6
  51. data/lib/moneta/synchronize.rb +3 -3
  52. data/lib/moneta/transformer.rb +19 -17
  53. data/lib/moneta/transformer/config.rb +6 -5
  54. data/lib/moneta/transformer/helper.rb +3 -3
  55. data/lib/moneta/transformer/helper/bson.rb +18 -15
  56. data/lib/moneta/utils.rb +3 -9
  57. data/lib/moneta/version.rb +1 -1
  58. data/lib/moneta/weak_each_key.rb +2 -4
  59. data/lib/rack/cache/moneta.rb +16 -13
  60. data/lib/rack/moneta_rest.rb +2 -2
  61. data/lib/rack/session/moneta.rb +3 -4
  62. data/moneta.gemspec +8 -0
  63. data/script/benchmarks +55 -32
  64. data/script/reconfigure-couchdb +13 -0
  65. data/script/start-hbase +1 -0
  66. data/script/start-services +2 -10
  67. data/spec/active_support/cache_moneta_store_spec.rb +3 -1
  68. data/spec/features/concurrent_create.rb +31 -10
  69. data/spec/features/concurrent_increment.rb +27 -19
  70. data/spec/features/increment.rb +41 -41
  71. data/spec/helper.rb +2 -42
  72. data/spec/moneta/adapters/activesupportcache/adapter_activesupportcache_spec.rb +4 -1
  73. data/spec/moneta/adapters/activesupportcache/adapter_activesupportcache_with_default_expires_spec.rb +4 -1
  74. data/spec/moneta/adapters/activesupportcache/standard_activesupportcache_spec.rb +14 -0
  75. data/spec/moneta/adapters/couch/adapter_couch_spec.rb +199 -2
  76. data/spec/moneta/adapters/couch/standard_couch_spec.rb +8 -2
  77. data/spec/moneta/adapters/couch/standard_couch_with_expires_spec.rb +7 -1
  78. data/spec/moneta/adapters/faraday_helper.rb +9 -0
  79. data/spec/moneta/adapters/lruhash/adapter_lruhash_spec.rb +2 -2
  80. data/spec/moneta/adapters/memcached/adapter_memcached_spec.rb +1 -1
  81. data/spec/moneta/adapters/memcached/dalli/adapter_memcached_dalli_spec.rb +1 -1
  82. data/spec/moneta/adapters/memcached/dalli/adapter_memcached_dalli_with_default_expires_spec.rb +1 -1
  83. data/spec/moneta/adapters/memcached/dalli/standard_memcached_dalli_spec.rb +1 -1
  84. data/spec/moneta/adapters/memcached/native/adapter_memcached_native_spec.rb +1 -1
  85. data/spec/moneta/adapters/memcached/native/adapter_memcached_native_with_default_expires_spec.rb +1 -1
  86. data/spec/moneta/adapters/memcached/native/standard_memcached_native_spec.rb +1 -1
  87. data/spec/moneta/adapters/memcached/standard_memcached_spec.rb +1 -1
  88. data/spec/moneta/adapters/{memcached/helper.rb → memcached_helper.rb} +0 -0
  89. data/spec/moneta/adapters/null/null_adapter_spec.rb +1 -1
  90. data/spec/moneta/adapters/restclient/adapter_restclient_spec.rb +7 -5
  91. data/spec/moneta/adapters/restclient/helper.rb +12 -0
  92. data/spec/moneta/adapters/restclient/standard_restclient_spec.rb +9 -6
  93. data/spec/moneta/adapters/riak/standard_riak_with_expires_spec.rb +4 -0
  94. data/spec/moneta/adapters/tokyotyrant/adapter_tokyotyrant_spec.rb +6 -2
  95. data/spec/moneta/adapters/tokyotyrant/helper.rb +12 -0
  96. data/spec/moneta/adapters/tokyotyrant/standard_tokyotyrant_spec.rb +5 -2
  97. data/spec/moneta/adapters/tokyotyrant/standard_tokyotyrant_with_expires_spec.rb +5 -1
  98. data/spec/moneta/proxies/enumerable/enumerable_spec.rb +26 -0
  99. data/spec/moneta/proxies/fallback/fallback_spec.rb +42 -0
  100. data/spec/moneta/proxies/pool/pool_spec.rb +319 -6
  101. data/spec/restserver.rb +40 -0
  102. metadata +122 -7
  103. data/script/install-kyotocabinet +0 -17
@@ -128,8 +128,8 @@ module Moneta
128
128
  end
129
129
 
130
130
  # (see Defaults::ClassMethods#not_supports)
131
- def not_supports *features
132
- @features_mask = (self.features_mask | features).freeze
131
+ def not_supports(*features)
132
+ @features_mask = (features_mask | features).freeze
133
133
  super
134
134
  end
135
135
  end
@@ -30,12 +30,10 @@ module Moneta
30
30
  @stop = false
31
31
  @running = true
32
32
  begin
33
- until @stop
34
- mainloop
35
- end
33
+ mainloop until @stop
36
34
  ensure
37
35
  File.unlink(@socket) if @socket
38
- @ios.each{ |io| io.close rescue nil }
36
+ @ios.each { |io| io.close rescue nil }
39
37
  end
40
38
  end
41
39
 
@@ -74,7 +72,7 @@ module Moneta
74
72
  rescue SignalException => ex
75
73
  warn "Moneta::Server - #{ex.message}"
76
74
  raise if ex.signo == 15 || ex.signo == 2 # SIGTERM or SIGINT
77
- rescue Exception => ex
75
+ rescue => ex
78
76
  warn "Moneta::Server - #{ex.message}"
79
77
  end
80
78
 
@@ -83,15 +81,14 @@ module Moneta
83
81
  @clients.delete(io)
84
82
  end
85
83
 
86
- def pack(o)
87
- s = Marshal.dump(o)
84
+ def pack(obj)
85
+ s = Marshal.dump(obj)
88
86
  [s.bytesize].pack('N') << s
89
87
  end
90
88
 
91
89
  def handle(io, buffer)
92
- buffer = @clients[io]
93
90
  return if buffer.bytesize < 8 # At least 4 bytes for the marshalled array
94
- size = buffer[0,4].unpack('N').first
91
+ size = buffer[0, 4].unpack('N').first
95
92
  if size > MAXSIZE
96
93
  delete_client(io)
97
94
  return
@@ -101,7 +98,7 @@ module Moneta
101
98
  method, *args = Marshal.load(buffer.slice!(0, size))
102
99
  case method
103
100
  when :key?, :load, :delete, :increment, :create
104
- io.write(pack @store.send(method, *args))
101
+ io.write(pack(@store.send(method, *args)))
105
102
  when :features
106
103
  # all features except each_key are supported
107
104
  io.write(pack(@store.features - [:each_key]))
@@ -114,9 +111,9 @@ module Moneta
114
111
  rescue IOError => ex
115
112
  warn "Moneta::Server - #{ex.message}" unless ex.message =~ /closed/
116
113
  delete_client(io)
117
- rescue Exception => ex
114
+ rescue => ex
118
115
  warn "Moneta::Server - #{ex.message}"
119
- io.write(pack Exception.new(ex.message))
116
+ io.write(pack(Exception.new(ex.message)))
120
117
  end
121
118
 
122
119
  def start(options)
@@ -42,7 +42,7 @@ module Moneta
42
42
  connect
43
43
  yield
44
44
  rescue Errno::ECONNRESET, Errno::EPIPE, IOError, SystemCallError
45
- @connect_lock.synchronize{ close unless @server }
45
+ @connect_lock.synchronize { close unless @server }
46
46
  tries ||= 0
47
47
  (tries += 1) < 3 ? retry : raise
48
48
  end
@@ -42,7 +42,7 @@ module Moneta
42
42
 
43
43
  # (see Proxy#key?)
44
44
  def key?(key, options = {})
45
- @stack.any? {|s| s.key?(key, options) }
45
+ @stack.any? { |s| s.key?(key, options) }
46
46
  end
47
47
 
48
48
  # (see Proxy#load)
@@ -56,21 +56,21 @@ module Moneta
56
56
 
57
57
  # (see Proxy#store)
58
58
  def store(key, value, options = {})
59
- @stack.each {|s| s.store(key, value, options) }
59
+ @stack.each { |s| s.store(key, value, options) }
60
60
  value
61
61
  end
62
62
 
63
63
  # (see Proxy#increment)
64
64
  def increment(key, amount = 1, options = {})
65
65
  last = nil
66
- @stack.each {|s| last = s.increment(key, amount, options) }
66
+ @stack.each { |s| last = s.increment(key, amount, options) }
67
67
  last
68
68
  end
69
69
 
70
70
  # (see Proxy#create)
71
71
  def create(key, value, options = {})
72
72
  last = false
73
- @stack.each {|s| last = s.create(key, value, options) }
73
+ @stack.each { |s| last = s.create(key, value, options) }
74
74
  last
75
75
  end
76
76
 
@@ -84,13 +84,13 @@ module Moneta
84
84
 
85
85
  # (see Proxy#clear)
86
86
  def clear(options = {})
87
- @stack.each {|s| s.clear(options) }
87
+ @stack.each { |s| s.clear(options) }
88
88
  self
89
89
  end
90
90
 
91
91
  # (see Proxy#close)
92
92
  def close
93
- @stack.each {|s| s.close }
93
+ @stack.each { |s| s.close }
94
94
  nil
95
95
  end
96
96
 
@@ -21,7 +21,7 @@ module Moneta
21
21
  raise 'Already locked' if @locked
22
22
  enter_primitive ? @locked = true : false
23
23
  end
24
- alias_method :try_lock, :try_enter
24
+ alias try_lock try_enter
25
25
 
26
26
  # Enter critical section (blocking)
27
27
  #
@@ -36,7 +36,7 @@ module Moneta
36
36
  end
37
37
  false
38
38
  end
39
- alias_method :lock, :enter
39
+ alias lock enter
40
40
 
41
41
  # Leave critical section
42
42
  def leave
@@ -45,7 +45,7 @@ module Moneta
45
45
  @locked = false
46
46
  nil
47
47
  end
48
- alias_method :unlock, :leave
48
+ alias unlock leave
49
49
 
50
50
  # Is the lock acquired?
51
51
  def locked?
@@ -19,7 +19,7 @@ module Moneta
19
19
  # @api public
20
20
  class Transformer < Proxy
21
21
  class << self
22
- alias_method :original_new, :new
22
+ alias original_new new
23
23
 
24
24
  # @param [Moneta store] adapter The underlying store
25
25
  # @param [Hash] options
@@ -49,13 +49,13 @@ module Moneta
49
49
  raise ArgumentError, 'Invalid value transformer chain' if @value_validator !~ values.map(&:inspect).join
50
50
 
51
51
  klass = Class.new(self)
52
- klass.class_eval <<-end_eval, __FILE__, __LINE__
52
+ klass.class_eval <<-END_EVAL, __FILE__, __LINE__ + 1
53
53
  def initialize(adapter, options = {})
54
54
  super
55
55
  #{compile_initializer('key', keys)}
56
56
  #{compile_initializer('value', values)}
57
57
  end
58
- end_eval
58
+ END_EVAL
59
59
 
60
60
  key, key_opts = compile_transformer(keys, 'key')
61
61
  dump, dump_opts = compile_transformer(values, 'value')
@@ -78,7 +78,7 @@ module Moneta
78
78
  end
79
79
 
80
80
  def compile_key_transformer(klass, key, key_opts)
81
- klass.class_eval <<-end_eval, __FILE__, __LINE__
81
+ klass.class_eval <<-END_EVAL, __FILE__, __LINE__ + 1
82
82
  not_supports :each_key
83
83
 
84
84
  def key?(key, options = {})
@@ -129,11 +129,11 @@ module Moneta
129
129
  @adapter.merge!(t_keys.zip(values), #{without :raw, key_opts}, &block)
130
130
  self
131
131
  end
132
- end_eval
132
+ END_EVAL
133
133
  end
134
134
 
135
135
  def compile_value_transformer(klass, load, load_opts, dump, dump_opts)
136
- klass.class_eval <<-end_eval, __FILE__, __LINE__
136
+ klass.class_eval <<-END_EVAL, __FILE__, __LINE__ + 1
137
137
  def load(key, options = {})
138
138
  value = @adapter.load(key, #{without :raw, load_opts})
139
139
  value && !options[:raw] ? #{load} : value
@@ -197,11 +197,11 @@ module Moneta
197
197
  @adapter.merge!(t_pairs, #{without :raw, dump_opts}, &block)
198
198
  self
199
199
  end
200
- end_eval
200
+ END_EVAL
201
201
  end
202
202
 
203
203
  def compile_key_value_transformer(klass, key, key_opts, load, load_opts, dump, dump_opts)
204
- klass.class_eval <<-end_eval, __FILE__, __LINE__
204
+ klass.class_eval <<-END_EVAL, __FILE__, __LINE__ + 1
205
205
  not_supports :each_key
206
206
 
207
207
  def key?(key, options = {})
@@ -292,7 +292,7 @@ module Moneta
292
292
  @adapter.merge!(t_pairs, #{without :raw, key_opts, dump_opts}, &block)
293
293
  self
294
294
  end
295
- end_eval
295
+ END_EVAL
296
296
  end
297
297
 
298
298
  # Compile option initializer
@@ -305,19 +305,21 @@ module Moneta
305
305
  end.join("\n")
306
306
  end
307
307
 
308
- def compile_validator(s)
309
- Regexp.new('\A' + s.gsub(/\w+/) do
310
- '(' + TRANSFORMER.select {|k,v| v.first.to_s == $& }.map {|v| ":#{v.first}" }.join('|') + ')'
311
- end.gsub(/\s+/, '') + '\Z')
308
+ def compile_validator(str)
309
+ Regexp.new('\A' +
310
+ str.gsub(/\w+/) do
311
+ '(' + TRANSFORMER.select { |_, v| v.first.to_s == $& }.map { |v| ":#{v.first}" }.join('|') + ')'
312
+ end.gsub(/\s+/, '') +
313
+ '\Z')
312
314
  end
313
315
 
314
316
  # Returned compiled transformer code string
315
- def compile_transformer(transformer, var, i = 2)
317
+ def compile_transformer(transformer, var, idx = 2)
316
318
  value, options = var, []
317
319
  transformer.each do |name|
318
320
  raise ArgumentError, "Unknown transformer #{name}" unless t = TRANSFORMER[name]
319
321
  require t[3] if t[3]
320
- code = t[i]
322
+ code = t[idx]
321
323
  options += code.scan(/options\[:(\w+)\]/).flatten
322
324
  value =
323
325
  if t[0] == :serialize && var == 'key'
@@ -326,11 +328,11 @@ module Moneta
326
328
  code % value
327
329
  end
328
330
  end
329
- return value, options
331
+ [value, options]
330
332
  end
331
333
 
332
334
  def class_name(keys, values)
333
- camel_case = lambda{ |sym| sym.to_s.split('_').map(&:capitalize).join }
335
+ camel_case = lambda { |sym| sym.to_s.split('_').map(&:capitalize).join }
334
336
  (keys.empty? ? '' : keys.map(&camel_case).join + 'Key') +
335
337
  (values.empty? ? '' : values.map(&camel_case).join + 'Value')
336
338
  end
@@ -22,7 +22,8 @@ module Moneta
22
22
  zlib: [ :compress, '::Zlib::Inflate.inflate(%s)', '::Zlib::Deflate.deflate(%s)', 'zlib' ],
23
23
  base64: [ :encode, "%s.unpack('m0').first", "[%s].pack('m0')" ],
24
24
  urlsafe_base64: [
25
- :encode, 'Base64.urlsafe_decode64(%s)', 'Base64.urlsafe_encode64(%s)', 'base64' ],
25
+ :encode, 'Base64.urlsafe_decode64(%s)', 'Base64.urlsafe_encode64(%s)', 'base64'
26
+ ],
26
27
  escape: [ :encode, 'Helper.unescape(%s)', 'Helper.escape(%s)' ],
27
28
  hex: [ :encode, "[%s].pack('H*')", "%s.unpack('H*').first" ],
28
29
  qp: [ :encode, "%s.unpack('M').first", "[%s].pack('M')" ],
@@ -42,13 +43,13 @@ module Moneta
42
43
  prefix: [ :prefix, nil, '(options[:prefix] || @prefix)+%s' ],
43
44
  spread: [ :spread, nil, 'Helper.spread(%s)' ],
44
45
  to_s: [ :string, nil, '%s.to_s' ],
45
- inspect: [ :string, nil, '%s.inspect' ],
46
- }
46
+ inspect: [ :string, nil, '%s.inspect' ]
47
+ }.freeze
47
48
 
48
49
  # Allowed value transformers (Read it like a regular expression!)
49
- VALUE_TRANSFORMER = 'serialize? compress? hmac? encode?'
50
+ VALUE_TRANSFORMER = 'serialize? compress? hmac? encode?'.freeze
50
51
 
51
52
  # Allowed key transformers (Read it like a regular expression!)
52
- KEY_TRANSFORMER = '(serialize | string)? prefix? ((encode? truncate?) | (digest spread?))?'
53
+ KEY_TRANSFORMER = '(serialize | string)? prefix? ((encode? truncate?) | (digest spread?))?'.freeze
53
54
  end
54
55
  end
@@ -5,11 +5,11 @@ module Moneta
5
5
  extend self
6
6
 
7
7
  def escape(value)
8
- value.gsub(/[^a-zA-Z0-9_-]+/){ '%' + $&.unpack('H2' * $&.bytesize).join('%').upcase }
8
+ value.gsub(/[^a-zA-Z0-9_-]+/) { '%' + $&.unpack('H2' * $&.bytesize).join('%').upcase }
9
9
  end
10
10
 
11
11
  def unescape(value)
12
- value.gsub(/((?:%[0-9a-fA-F]{2})+)/){ [$1.delete('%')].pack('H*') }
12
+ value.gsub(/((?:%[0-9a-fA-F]{2})+)/) { |matches| [matches[1].delete('%')].pack('H*') }
13
13
  end
14
14
 
15
15
  def hmacverify(value, secret)
@@ -24,7 +24,7 @@ module Moneta
24
24
  def truncate(value, maxlen)
25
25
  if value.size >= maxlen
26
26
  digest = Digest::MD5.hexdigest(value)
27
- value = value[0, maxlen-digest.size] << digest
27
+ value = value[0, maxlen - digest.size] << digest
28
28
  end
29
29
  value
30
30
  end
@@ -1,23 +1,26 @@
1
1
  module Moneta
2
2
  class Transformer
3
- module Helper::BSON
4
- extend self
3
+ module Helper
4
+ # @api private
5
+ module BSON
6
+ extend self
5
7
 
6
- if ::BSON::VERSION >= '4.0.0'
7
- def load value
8
- ::BSON::Document.from_bson(::BSON::ByteBuffer.new(value))['v']
9
- end
8
+ if ::BSON::VERSION >= '4.0.0'
9
+ def load(value)
10
+ ::BSON::Document.from_bson(::BSON::ByteBuffer.new(value))['v']
11
+ end
10
12
 
11
- def dump value
12
- ::BSON::Document['v'=>value].to_bson.to_s
13
- end
14
- else
15
- def load value
16
- ::BSON::Document.from_bson(::StringIO.new(value))['v']
17
- end
13
+ def dump(value)
14
+ ::BSON::Document['v' => value].to_bson.to_s
15
+ end
16
+ else
17
+ def load(value)
18
+ ::BSON::Document.from_bson(::StringIO.new(value))['v']
19
+ end
18
20
 
19
- def dump value
20
- ::BSON::Document['v'=>value].to_bson
21
+ def dump(value)
22
+ ::BSON::Document['v' => value].to_bson
23
+ end
21
24
  end
22
25
  end
23
26
  end
@@ -5,9 +5,9 @@ module Moneta
5
5
 
6
6
  def without(hash, *keys)
7
7
  return hash if hash.empty?
8
- if keys.any? {|k| hash.include?(k) }
8
+ if keys.any? { |k| hash.include?(k) }
9
9
  hash = hash.dup
10
- keys.each {|k| hash.delete(k) }
10
+ keys.each { |k| hash.delete(k) }
11
11
  end
12
12
  hash
13
13
  end
@@ -15,14 +15,8 @@ module Moneta
15
15
  def only(hash, *keys)
16
16
  return hash if hash.empty?
17
17
  ret = {}
18
- keys.each {|k| ret[k] = hash[k] }
18
+ keys.each { |k| ret[k] = hash[k] }
19
19
  ret
20
20
  end
21
-
22
- def to_int(value)
23
- intvalue = value.to_i
24
- raise "#{value.inspect} is not an integer value" unless value == nil || intvalue.to_s == value.to_s
25
- intvalue
26
- end
27
21
  end
28
22
  end
@@ -1,5 +1,5 @@
1
1
  module Moneta
2
2
  # Moneta version number
3
3
  # @api public
4
- VERSION = '1.1.1'
4
+ VERSION = '1.2.0'.freeze
5
5
  end
@@ -31,6 +31,8 @@ module Moneta
31
31
 
32
32
  protected
33
33
 
34
+ attr_reader :all_keys
35
+
34
36
  def wrap(name, *args)
35
37
  case name
36
38
  when :create, :store, :increment, :create
@@ -63,10 +65,6 @@ module Moneta
63
65
  end
64
66
  end
65
67
 
66
- def all_keys
67
- @all_keys
68
- end
69
-
70
68
  def each_key_save(key)
71
69
  @all_keys = Set.new(@all_keys).add(key)
72
70
  end
@@ -14,18 +14,21 @@ module Rack
14
14
 
15
15
  def resolve(uri)
16
16
  cache = Rack::Cache::Moneta[uri.to_s.sub(%r{^moneta://}, '')] ||=
17
- begin
18
- options = parse_query(uri.query)
19
- options.keys.each do |key|
20
- options[key.to_sym] =
21
- case value = options.delete(key)
22
- when 'true'; true
23
- when 'false'; false
24
- else value
25
- end
26
- end
27
- ::Moneta.new(uri.host.to_sym, options)
28
- end
17
+ begin
18
+ options = parse_query(uri.query)
19
+ options.keys.each do |key|
20
+ options[key.to_sym] =
21
+ case value = options.delete(key)
22
+ when 'true'
23
+ true
24
+ when 'false'
25
+ false
26
+ else
27
+ value
28
+ end
29
+ end
30
+ ::Moneta.new(uri.host.to_sym, options)
31
+ end
29
32
  new(cache)
30
33
  end
31
34
  end
@@ -82,7 +85,7 @@ module Rack
82
85
  def write(body, ttl = 0)
83
86
  buf = StringIO.new
84
87
  key, size = slurp(body) { |part| buf.write(part) }
85
- @cache.store(key, buf.string, ttl == 0 ? {} : {expires: ttl})
88
+ @cache.store(key, buf.string, ttl == 0 ? {} : { expires: ttl })
86
89
  [key, size]
87
90
  end
88
91