moneta 0.7.15 → 0.7.16

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.
data/.travis.yml CHANGED
@@ -9,7 +9,7 @@ rvm:
9
9
  # - rbx-18mode
10
10
  before_install:
11
11
  - script/kill-travis
12
- - script/install-kyotocabinet
12
+ #- script/install-kyotocabinet
13
13
  - sudo apt-get install -qq libtokyocabinet8 libtokyocabinet-dev liblzo2-dev libtdb-dev tokyotyrant
14
14
  - script/start-services
15
15
  - script/install-bundle
@@ -41,9 +41,7 @@ matrix:
41
41
  - rvm: jruby-19mode
42
42
  - rvm: rbx-18mode
43
43
  - rvm: rbx-19mode
44
- - env:
45
- - "TASK=test TEST_GROUP=unstable"
46
- - secure: "B0vx1g1CB1A6mM3B/iy2ATicfS4OXT80bb2RVe8mSRsPzez1B4q4Q4hJcaMI\nrMARONN8Krtnti+IqvmDnB0Z0AKYMEyIc+zT37zJOCjLdkLJl+x/thuU/MbC\nvlLVwjMf6JE2EUzTfORDRFYc5ycCqfsfgNk1Go0D2CPT6P9u9uQ="
44
+ - env: "TASK=test TEST_GROUP=unstable"
47
45
  script: "bundle exec rake $TASK"
48
46
  branches:
49
47
  only:
data/Gemfile CHANGED
@@ -50,11 +50,11 @@ gem 'leveldb-ruby', :platforms => :ruby
50
50
  if RUBY_VERSION < '2.0'
51
51
  gem 'tokyocabinet', :platforms => :ruby
52
52
  end
53
- if RUBY_VERSION < '2.0' && !defined?(JRUBY_VERSION)
53
+ #if RUBY_VERSION < '2.0' && !defined?(JRUBY_VERSION)
54
54
  # FIXME: We have to check manually for jruby
55
55
  # otherwise bundle install --deployment doesn't work
56
- gem 'kyotocabinet-ruby', :github => 'minad/kyotocabinet-ruby'
57
- end
56
+ # gem 'kyotocabinet-ruby', :github => 'minad/kyotocabinet-ruby'
57
+ #end
58
58
  gem 'memcached', :platforms => :ruby
59
59
  gem 'jruby-memcached', :platforms => :jruby
60
60
  gem 'sqlite3', :platforms => :ruby
data/README.md CHANGED
@@ -323,8 +323,12 @@ If you want to have control over the proxies, you have to use `Moneta.build`:
323
323
  store = Moneta.build do
324
324
  # Adds expires proxy
325
325
  use :Expires
326
+
326
327
  # Transform key using Marshal and Base64 and value using Marshal
327
328
  use :Transformer, :key => [:marshal, :base64], :value => :marshal
329
+
330
+ # IMPORTANT: adapter must be defined last for the builder to function properly.
331
+
328
332
  # Memory backend
329
333
  adapter :Memory
330
334
  end
data/Rakefile CHANGED
@@ -35,7 +35,7 @@ task :test do
35
35
  #
36
36
  # * PStore and File increment/locking doesn't work correctly on JRuby
37
37
  #
38
- unstable = %w(quicklz)
38
+ unstable = %w(quicklz riak)
39
39
  unstable += %w(file pstore) if defined?(JRUBY_VERSION)
40
40
 
41
41
  unstable_re = /#{unstable.join('|')}/
@@ -7,6 +7,10 @@ module Moneta
7
7
  class Sequel
8
8
  include Defaults
9
9
 
10
+ # Sequel::UniqueConstraintViolation is defined since sequel 3.44.0
11
+ # older versions raise a Sequel::DatabaseError.
12
+ UniqueConstraintViolation = defined?(::Sequel::UniqueConstraintViolation) ? ::Sequel::UniqueConstraintViolation : ::Sequel::DatabaseError
13
+
10
14
  supports :create, :increment
11
15
  attr_reader :backend
12
16
 
@@ -44,7 +48,7 @@ module Moneta
44
48
  def store(key, value, options = {})
45
49
  begin
46
50
  @table.insert(:k => key, :v => value)
47
- rescue ::Sequel::DatabaseError
51
+ rescue UniqueConstraintViolation
48
52
  @table.where(:k => key).update(:v => value)
49
53
  end
50
54
  value
@@ -57,9 +61,7 @@ module Moneta
57
61
  def create(key, value, options = {})
58
62
  @table.insert(:k => key, :v => value)
59
63
  true
60
- rescue ::Sequel::DatabaseError
61
- # FIXME: This catches too many errors
62
- # it should only catch a not-unique-exception
64
+ rescue UniqueConstraintViolation
63
65
  false
64
66
  end
65
67
 
@@ -77,8 +79,7 @@ module Moneta
77
79
  end
78
80
  end
79
81
  rescue ::Sequel::DatabaseError
80
- # FIXME: This catches too many errors
81
- # it should only catch a not-unique-exception
82
+ # Concurrent modification might throw a bunch of different errors
82
83
  tries ||= 0
83
84
  (tries += 1) < 10 ? retry : raise
84
85
  end
@@ -17,11 +17,14 @@ module Moneta
17
17
  adapter = @proxies.first
18
18
  if Array === adapter
19
19
  klass, options, block = adapter
20
- adapter = klass.new(options, &block)
20
+ adapter = new_proxy(klass, options, &block)
21
+ check_arity(klass, adapter, 1)
21
22
  end
22
- @proxies[1..-1].inject([adapter]) do |stores, proxy|
23
+ @proxies[1..-1].inject([adapter]) do |result, proxy|
23
24
  klass, options, block = proxy
24
- stores << klass.new(stores.last, options, &block)
25
+ proxy = new_proxy(klass, result.last, options, &block)
26
+ check_arity(klass, proxy, 2)
27
+ result << proxy
25
28
  end
26
29
  end
27
30
 
@@ -55,5 +58,26 @@ module Moneta
55
58
  nil
56
59
  end
57
60
  end
61
+
62
+ protected
63
+
64
+ def new_proxy(klass, *args, &block)
65
+ klass.new(*args, &block)
66
+ rescue ArgumentError => ex
67
+ check_arity(klass, klass.allocate, args.size)
68
+ raise
69
+ end
70
+
71
+ def check_arity(klass, proxy, expected)
72
+ args = proxy.method(:initialize).arity.abs
73
+ raise(ArgumentError, %{#{klass.name}#new accepts wrong number of arguments (#{args} accepted, #{expected} expected)
74
+
75
+ Please check your Moneta builder block:
76
+ * Proxies must be used before the adapter
77
+ * Only one adapter is allowed
78
+ * The adapter must be used last
79
+ }) if args != expected
80
+ end
58
81
  end
82
+
59
83
  end
@@ -1,5 +1,5 @@
1
1
  module Moneta
2
2
  # Moneta version number
3
3
  # @api public
4
- VERSION = '0.7.15'
4
+ VERSION = '0.7.16'
5
5
  end
@@ -0,0 +1,29 @@
1
+ require 'moneta'
2
+ describe Moneta::Builder do
3
+ it 'raises an error if #use is called after #adapter' do
4
+ expect do
5
+ Moneta::Builder.new do
6
+ adapter :Null
7
+ use :Lock
8
+ end.build
9
+ end.to raise_error /Please check/
10
+ end
11
+
12
+ it 'raises an error if #adapter called twice' do
13
+ expect do
14
+ Moneta::Builder.new do
15
+ adapter :Null
16
+ adapter :Null
17
+ end.build
18
+ end.to raise_error /Please check/
19
+ end
20
+
21
+ it 'raises an error if no #adapter is specified' do
22
+ expect do
23
+ Moneta::Builder.new do
24
+ use :Lock
25
+ use :Lock
26
+ end.build
27
+ end.to raise_error /Please check/
28
+ end
29
+ end
metadata CHANGED
@@ -1,30 +1,39 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: moneta
3
- version: !ruby/object:Gem::Version
4
- version: 0.7.15
3
+ version: !ruby/object:Gem::Version
4
+ hash: 35
5
5
  prerelease:
6
+ segments:
7
+ - 0
8
+ - 7
9
+ - 16
10
+ version: 0.7.16
6
11
  platform: ruby
7
- authors:
12
+ authors:
8
13
  - Daniel Mendler
9
14
  - Yehuda Katz
10
15
  - Hannes Georg
11
16
  autorequire:
12
17
  bindir: bin
13
18
  cert_chain: []
14
- date: 2013-04-04 00:00:00.000000000 Z
19
+
20
+ date: 2013-05-23 00:00:00 Z
15
21
  dependencies: []
22
+
16
23
  description: A unified interface to key/value stores
17
- email:
24
+ email:
18
25
  - mail@daniel-mendler.de
19
26
  - wycats@gmail.com
20
27
  - hannes.georg@googlemail.com
21
28
  executables: []
29
+
22
30
  extensions: []
23
- extra_rdoc_files:
31
+
32
+ extra_rdoc_files:
24
33
  - README.md
25
34
  - SPEC.md
26
35
  - LICENSE
27
- files:
36
+ files:
28
37
  - .gitignore
29
38
  - .travis.yml
30
39
  - .yardopts
@@ -149,6 +158,7 @@ files:
149
158
  - spec/moneta/adapter_tokyocabinet_hdb_spec.rb
150
159
  - spec/moneta/adapter_tokyotyrant_spec.rb
151
160
  - spec/moneta/adapter_yaml_spec.rb
161
+ - spec/moneta/builder_spec.rb
152
162
  - spec/moneta/cache_file_memory_spec.rb
153
163
  - spec/moneta/cache_memory_null_spec.rb
154
164
  - spec/moneta/expires_file_spec.rb
@@ -275,30 +285,38 @@ files:
275
285
  - spec/rack/session_moneta_spec.rb
276
286
  homepage: http://github.com/minad/moneta
277
287
  licenses: []
288
+
278
289
  post_install_message:
279
290
  rdoc_options: []
280
- require_paths:
291
+
292
+ require_paths:
281
293
  - lib
282
- required_ruby_version: !ruby/object:Gem::Requirement
294
+ required_ruby_version: !ruby/object:Gem::Requirement
283
295
  none: false
284
- requirements:
285
- - - ! '>='
286
- - !ruby/object:Gem::Version
287
- version: '0'
288
- required_rubygems_version: !ruby/object:Gem::Requirement
296
+ requirements:
297
+ - - ">="
298
+ - !ruby/object:Gem::Version
299
+ hash: 3
300
+ segments:
301
+ - 0
302
+ version: "0"
303
+ required_rubygems_version: !ruby/object:Gem::Requirement
289
304
  none: false
290
- requirements:
291
- - - ! '>='
292
- - !ruby/object:Gem::Version
293
- version: '0'
305
+ requirements:
306
+ - - ">="
307
+ - !ruby/object:Gem::Version
308
+ hash: 3
309
+ segments:
310
+ - 0
311
+ version: "0"
294
312
  requirements: []
313
+
295
314
  rubyforge_project:
296
315
  rubygems_version: 1.8.24
297
316
  signing_key:
298
317
  specification_version: 3
299
- summary: A unified interface to key/value stores, including Redis, Memcached, TokyoCabinet,
300
- ActiveRecord and many more
301
- test_files:
318
+ summary: A unified interface to key/value stores, including Redis, Memcached, TokyoCabinet, ActiveRecord and many more
319
+ test_files:
302
320
  - spec/action_dispatch/fixtures/session_autoload_test/foo.rb
303
321
  - spec/action_dispatch/session_moneta_store_spec.rb
304
322
  - spec/active_support/cache_moneta_store_spec.rb
@@ -343,6 +361,7 @@ test_files:
343
361
  - spec/moneta/adapter_tokyocabinet_hdb_spec.rb
344
362
  - spec/moneta/adapter_tokyotyrant_spec.rb
345
363
  - spec/moneta/adapter_yaml_spec.rb
364
+ - spec/moneta/builder_spec.rb
346
365
  - spec/moneta/cache_file_memory_spec.rb
347
366
  - spec/moneta/cache_memory_null_spec.rb
348
367
  - spec/moneta/expires_file_spec.rb