active_record_mutex 2.0.0 → 2.2.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: 6401837d63b0c70a4c0e1cb8c0a6a4cb9c05761c
4
- data.tar.gz: 8277512688081db3c74b963736e68f559995b427
3
+ metadata.gz: 57edd5b2783fbaca9577d0d8844995db0da452af
4
+ data.tar.gz: f10aceb1edeb6b41e44fdab8d64121bc9b409bfc
5
5
  SHA512:
6
- metadata.gz: 4dcb37cb5b17af31b5c6c808370e840b2d1e8172614027886c0e8fefcd554788b45e0fce4c93e688534924ebd51698efdf955b07483c1d2fd5b806586652bd60
7
- data.tar.gz: d71542f82f69f4eb426891750e95b87bf92dc538d9dfa8571c1f3188fc9d7a09976c46137e0319ddcc20d5cb11cebebffa47c7f03b1aa2c25e148861ded2d9ea
6
+ metadata.gz: d427e2a1befb62f430afd4f2dcf648f797ea8782147161d867188ec606ce8b0c23d0b0f48427c508381a19103257c94170a0a46ed5c3706814e40e360a87c013
7
+ data.tar.gz: fc1165348c415d5561c6b0607555697082aa1339e17e14a93a24b0f0ea225703a9d7c461189be949d23a0ac598c9a8f30c7b850fb42dad41ca69827fa400fb08
data/.gitignore CHANGED
@@ -1,5 +1,6 @@
1
1
  .*.sw[pon]
2
2
  .DS_Store
3
+ .byebug_history
3
4
  Gemfile.lock
4
5
  coverage
5
6
  pkg
@@ -11,3 +11,4 @@ before_script:
11
11
  - mysql -e 'create database test;'
12
12
  env:
13
13
  - CODECLIMATE_REPO_TOKEN=316615e61480039c3444f59bf124cf810d31110326e51f133e9cc9852de14892
14
+ sudo: false
data/README.md CHANGED
@@ -42,6 +42,7 @@ Now you can send all messages directly to the Mutex instance.
42
42
 
43
43
  ## Changes
44
44
 
45
+ * 2016-08-19 Make locks rails environments independent
45
46
  * 2014-12-12 Release 2.0.0
46
47
  * 2014-12-12 Add license information
47
48
  * 2014-12-09 Adapt to newer Rails versions' API
data/Rakefile CHANGED
@@ -12,12 +12,13 @@ GemHadar do
12
12
  description 'Mutex that can be used to synchronise ruby processes via an ActiveRecord'\
13
13
  ' datababase connection. (Only Mysql is supported at the moment.)'
14
14
  test_dir 'test'
15
- ignore '.*.sw[pon]', 'pkg', 'Gemfile.lock', '.DS_Store', 'coverage'
15
+ ignore '.*.sw[pon]', 'pkg', 'Gemfile.lock', '.DS_Store', 'coverage',
16
+ '.byebug_history'
16
17
  readme 'README.md'
17
18
  licenses << 'GPL-2'
18
19
 
19
20
  dependency 'mysql2', '~>0.3.0'
20
- dependency 'activerecord'
21
+ dependency 'activerecord', '~> 4.0'
21
22
  development_dependency 'test-unit', '~>3.0'
22
23
  development_dependency 'byebug'
23
24
  development_dependency 'simplecov'
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.0.0
1
+ 2.2.0
@@ -1,22 +1,22 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: active_record_mutex 2.0.0 ruby lib
2
+ # stub: active_record_mutex 2.2.0 ruby lib
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "active_record_mutex"
6
- s.version = "2.0.0"
6
+ s.version = "2.2.0"
7
7
 
8
8
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
9
9
  s.require_paths = ["lib"]
10
10
  s.authors = ["Florian Frank"]
11
- s.date = "2014-12-12"
11
+ s.date = "2016-08-19"
12
12
  s.description = "Mutex that can be used to synchronise ruby processes via an ActiveRecord datababase connection. (Only Mysql is supported at the moment.)"
13
13
  s.email = "flori@ping.de"
14
14
  s.extra_rdoc_files = ["README.md", "lib/active_record/database_mutex.rb", "lib/active_record/database_mutex/implementation.rb", "lib/active_record/database_mutex/version.rb", "lib/active_record/mutex.rb", "lib/active_record_mutex.rb"]
15
- s.files = [".gitignore", ".travis.yml", "CHANGES", "COPYING", "Gemfile", "README.md", "Rakefile", "VERSION", "active_record_mutex.gemspec", "lib/active_record/database_mutex.rb", "lib/active_record/database_mutex/implementation.rb", "lib/active_record/database_mutex/version.rb", "lib/active_record/mutex.rb", "lib/active_record_mutex.rb", "test/database_mutex_test.rb", "test/test_helper.rb"]
15
+ s.files = [".gitignore", ".travis.yml", "COPYING", "Gemfile", "README.md", "Rakefile", "VERSION", "active_record_mutex.gemspec", "lib/active_record/database_mutex.rb", "lib/active_record/database_mutex/implementation.rb", "lib/active_record/database_mutex/version.rb", "lib/active_record/mutex.rb", "lib/active_record_mutex.rb", "test/database_mutex_test.rb", "test/test_helper.rb"]
16
16
  s.homepage = "http://github.com/flori/active_record_mutex"
17
17
  s.licenses = ["GPL-2"]
18
18
  s.rdoc_options = ["--title", "ActiveRecordMutex - Implementation of a Mutex for Active Record", "--main", "README.md"]
19
- s.rubygems_version = "2.4.4"
19
+ s.rubygems_version = "2.5.1"
20
20
  s.summary = "Implementation of a Mutex for Active Record"
21
21
  s.test_files = ["test/database_mutex_test.rb", "test/test_helper.rb"]
22
22
 
@@ -24,26 +24,26 @@ Gem::Specification.new do |s|
24
24
  s.specification_version = 4
25
25
 
26
26
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
27
- s.add_development_dependency(%q<gem_hadar>, ["~> 0.3.2"])
27
+ s.add_development_dependency(%q<gem_hadar>, ["~> 1.7.1"])
28
28
  s.add_development_dependency(%q<test-unit>, ["~> 3.0"])
29
29
  s.add_development_dependency(%q<byebug>, [">= 0"])
30
30
  s.add_development_dependency(%q<simplecov>, [">= 0"])
31
31
  s.add_runtime_dependency(%q<mysql2>, ["~> 0.3.0"])
32
- s.add_runtime_dependency(%q<activerecord>, [">= 0"])
32
+ s.add_runtime_dependency(%q<activerecord>, ["~> 4.0"])
33
33
  else
34
- s.add_dependency(%q<gem_hadar>, ["~> 0.3.2"])
34
+ s.add_dependency(%q<gem_hadar>, ["~> 1.7.1"])
35
35
  s.add_dependency(%q<test-unit>, ["~> 3.0"])
36
36
  s.add_dependency(%q<byebug>, [">= 0"])
37
37
  s.add_dependency(%q<simplecov>, [">= 0"])
38
38
  s.add_dependency(%q<mysql2>, ["~> 0.3.0"])
39
- s.add_dependency(%q<activerecord>, [">= 0"])
39
+ s.add_dependency(%q<activerecord>, ["~> 4.0"])
40
40
  end
41
41
  else
42
- s.add_dependency(%q<gem_hadar>, ["~> 0.3.2"])
42
+ s.add_dependency(%q<gem_hadar>, ["~> 1.7.1"])
43
43
  s.add_dependency(%q<test-unit>, ["~> 3.0"])
44
44
  s.add_dependency(%q<byebug>, [">= 0"])
45
45
  s.add_dependency(%q<simplecov>, [">= 0"])
46
46
  s.add_dependency(%q<mysql2>, ["~> 0.3.0"])
47
- s.add_dependency(%q<activerecord>, [">= 0"])
47
+ s.add_dependency(%q<activerecord>, ["~> 4.0"])
48
48
  end
49
49
  end
@@ -17,7 +17,7 @@ module ActiveRecord
17
17
  # moment and lock was called again.
18
18
  class MutexLocked < MutexError; end
19
19
 
20
- class MutexInvalidState < MutexError; end
20
+ class MutexInvalidState < MutexError; end
21
21
 
22
22
  def self.included(modul)
23
23
  modul.instance_eval do
@@ -25,7 +25,7 @@ module ActiveRecord
25
25
  end
26
26
  end
27
27
 
28
- # XXX
28
+ # Return a mutex implementation for the mutex named +name+.
29
29
  def self.for(name)
30
30
  Implementation.new(:name => name)
31
31
  end
@@ -33,7 +33,9 @@ module ActiveRecord
33
33
  module ClassMethods
34
34
  # Returns a mutex instance for this ActiveRecord subclass.
35
35
  def mutex
36
- @mutex ||= Implementation.new(:name => name)
36
+ @mutex ||= Implementation.new(
37
+ :name => [ name, ENV['RAILS_ENV'] ].compact * ?@
38
+ )
37
39
  end
38
40
  end
39
41
 
@@ -24,13 +24,12 @@ module ActiveRecord
24
24
  # ends after that many seconds and the method returns immediately if the
25
25
  # lock couldn't be aquired during that time.
26
26
  def synchronize(opts = {})
27
- locked_before = aquired_lock?
28
27
  locked = lock(opts) or return
29
28
  yield
30
29
  rescue ActiveRecord::DatabaseMutex::MutexLocked
31
30
  return nil
32
31
  ensure
33
- locked_before or locked && unlock
32
+ locked && unlock
34
33
  end
35
34
 
36
35
  # Locks the mutex and returns true if successful. If the mutex is
@@ -65,7 +64,8 @@ module ActiveRecord
65
64
  end
66
65
  end
67
66
 
68
- # XXX
67
+ # Unlock this mutex and return self if successful, otherwise (the mutex
68
+ # was not locked) nil is returned.
69
69
  def unlock?(*a)
70
70
  unlock(*a)
71
71
  self
@@ -1,6 +1,6 @@
1
1
  module ActiveRecord::DatabaseMutex
2
2
  # ActiveRecord::DatabaseMutex version
3
- VERSION = '2.0.0'
3
+ VERSION = '2.2.0'
4
4
  VERSION_ARRAY = VERSION.split('.').map(&:to_i) # :nodoc:
5
5
  VERSION_MAJOR = VERSION_ARRAY[0] # :nodoc:
6
6
  VERSION_MINOR = VERSION_ARRAY[1] # :nodoc:
@@ -17,10 +17,28 @@ class DatabaseMutexTest < Test::Unit::TestCase
17
17
  end
18
18
  end
19
19
 
20
- def test_class_methods
20
+ def test_class_method_mutex
21
+ old, ENV['RAILS_ENV'] = ENV['RAILS_ENV'], nil
22
+ Foo.instance_eval do
23
+ @mutex = nil
24
+ end
21
25
  mutex = Foo.mutex
22
26
  assert_kind_of ActiveRecord::DatabaseMutex::Implementation, mutex
23
- assert_equal mutex.name, Foo.name
27
+ assert_equal Foo.name, mutex.name
28
+ ensure
29
+ ENV['RAILS_ENV'] = old
30
+ end
31
+
32
+ def test_class_method_mutex_within_env
33
+ old, ENV['RAILS_ENV'] = ENV['RAILS_ENV'], 'test'
34
+ Foo.instance_eval do
35
+ @mutex = nil
36
+ end
37
+ mutex = Foo.mutex
38
+ assert_kind_of ActiveRecord::DatabaseMutex::Implementation, mutex
39
+ assert_equal "#{Foo.name}@test", mutex.name
40
+ ensure
41
+ ENV['RAILS_ENV'] = old
24
42
  end
25
43
 
26
44
  def test_instance_method
@@ -31,7 +49,7 @@ class DatabaseMutexTest < Test::Unit::TestCase
31
49
  assert_equal true, instance.save
32
50
  mutex = instance.mutex
33
51
  assert_kind_of ActiveRecord::DatabaseMutex::Implementation, mutex
34
- assert_equal mutex.name, "#{instance.id}@#{Foo.name}"
52
+ assert_equal "#{instance.id}@#{Foo.name}", mutex.name
35
53
  end
36
54
 
37
55
  def test_factory_method_for
@@ -101,4 +119,12 @@ class DatabaseMutexTest < Test::Unit::TestCase
101
119
  end
102
120
  assert mutex.unlocked?
103
121
  end
122
+
123
+ def test_synchronize_already_locked
124
+ mutex = Implementation.new(:name => 'Sync4')
125
+ def mutex.lock(*)
126
+ raise ActiveRecord::DatabaseMutex::MutexLocked
127
+ end
128
+ assert_nil mutex.synchronize {}
129
+ end
104
130
  end
@@ -2,9 +2,15 @@ if ENV.key?('CODECLIMATE_REPO_TOKEN')
2
2
  require "codeclimate-test-reporter"
3
3
  CodeClimate::TestReporter.start
4
4
  end
5
+ if ENV['START_SIMPLECOV'].to_i == 1
6
+ require 'simplecov'
7
+ SimpleCov.start do
8
+ add_filter "#{File.basename(File.dirname(__FILE__))}/"
9
+ end
10
+ end
5
11
 
6
- $:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
7
12
  require 'active_record'
13
+ $:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
8
14
  require 'active_record/database_mutex'
9
15
 
10
16
  ActiveRecord::Base.establish_connection(
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_record_mutex
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Florian Frank
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-12 00:00:00.000000000 Z
11
+ date: 2016-08-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gem_hadar
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.3.2
19
+ version: 1.7.1
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.3.2
26
+ version: 1.7.1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: test-unit
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -84,16 +84,16 @@ dependencies:
84
84
  name: activerecord
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ">="
87
+ - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '0'
89
+ version: '4.0'
90
90
  type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - ">="
94
+ - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: '0'
96
+ version: '4.0'
97
97
  description: Mutex that can be used to synchronise ruby processes via an ActiveRecord
98
98
  datababase connection. (Only Mysql is supported at the moment.)
99
99
  email: flori@ping.de
@@ -109,7 +109,6 @@ extra_rdoc_files:
109
109
  files:
110
110
  - ".gitignore"
111
111
  - ".travis.yml"
112
- - CHANGES
113
112
  - COPYING
114
113
  - Gemfile
115
114
  - README.md
@@ -147,7 +146,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
147
146
  version: '0'
148
147
  requirements: []
149
148
  rubyforge_project:
150
- rubygems_version: 2.4.4
149
+ rubygems_version: 2.5.1
151
150
  signing_key:
152
151
  specification_version: 4
153
152
  summary: Implementation of a Mutex for Active Record
data/CHANGES DELETED
File without changes