active_record_mutex 1.0.1 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 10f7287df270aea08ad6b2816d16b2f379cf71e0
4
- data.tar.gz: 0970e00bb106ad24c9e504c72e4b249d55c2ec09
3
+ metadata.gz: 6401837d63b0c70a4c0e1cb8c0a6a4cb9c05761c
4
+ data.tar.gz: 8277512688081db3c74b963736e68f559995b427
5
5
  SHA512:
6
- metadata.gz: 11770e3b7f16ae9f4db32009622d10dc795df0089c809c3f97c481fd00a4573b7ab6f74e7faf153b66c8d3d6b9d9630f78ff9cb541f02b2e1e075e88951f5980
7
- data.tar.gz: e6f1d08f02a2c876f1919b19ee17eeb74c6f48ffb1e66310e270411067bd849ecd5110b7c33c29a1fd84f54ce9684e877e81b369ef1ea6bf1c11de3a50739fc2
6
+ metadata.gz: 4dcb37cb5b17af31b5c6c808370e840b2d1e8172614027886c0e8fefcd554788b45e0fce4c93e688534924ebd51698efdf955b07483c1d2fd5b806586652bd60
7
+ data.tar.gz: d71542f82f69f4eb426891750e95b87bf92dc538d9dfa8571c1f3188fc9d7a09976c46137e0319ddcc20d5cb11cebebffa47c7f03b1aa2c25e148861ded2d9ea
data/.gitignore CHANGED
@@ -1,3 +1,5 @@
1
1
  .*.sw[pon]
2
+ .DS_Store
2
3
  Gemfile.lock
4
+ coverage
3
5
  pkg
data/.travis.yml ADDED
@@ -0,0 +1,13 @@
1
+ rvm:
2
+ - 2.0.0
3
+ - 2.1
4
+ - ruby-head
5
+ - jruby-head
6
+ matrix:
7
+ allow_failures:
8
+ - rvm: ruby-head
9
+ - rvm: jruby-head
10
+ before_script:
11
+ - mysql -e 'create database test;'
12
+ env:
13
+ - CODECLIMATE_REPO_TOKEN=316615e61480039c3444f59bf124cf810d31110326e51f133e9cc9852de14892
data/COPYING ADDED
@@ -0,0 +1,339 @@
1
+ GNU GENERAL PUBLIC LICENSE
2
+ Version 2, June 1991
3
+
4
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
5
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
6
+ Everyone is permitted to copy and distribute verbatim copies
7
+ of this license document, but changing it is not allowed.
8
+
9
+ Preamble
10
+
11
+ The licenses for most software are designed to take away your
12
+ freedom to share and change it. By contrast, the GNU General Public
13
+ License is intended to guarantee your freedom to share and change free
14
+ software--to make sure the software is free for all its users. This
15
+ General Public License applies to most of the Free Software
16
+ Foundation's software and to any other program whose authors commit to
17
+ using it. (Some other Free Software Foundation software is covered by
18
+ the GNU Lesser General Public License instead.) You can apply it to
19
+ your programs, too.
20
+
21
+ When we speak of free software, we are referring to freedom, not
22
+ price. Our General Public Licenses are designed to make sure that you
23
+ have the freedom to distribute copies of free software (and charge for
24
+ this service if you wish), that you receive source code or can get it
25
+ if you want it, that you can change the software or use pieces of it
26
+ in new free programs; and that you know you can do these things.
27
+
28
+ To protect your rights, we need to make restrictions that forbid
29
+ anyone to deny you these rights or to ask you to surrender the rights.
30
+ These restrictions translate to certain responsibilities for you if you
31
+ distribute copies of the software, or if you modify it.
32
+
33
+ For example, if you distribute copies of such a program, whether
34
+ gratis or for a fee, you must give the recipients all the rights that
35
+ you have. You must make sure that they, too, receive or can get the
36
+ source code. And you must show them these terms so they know their
37
+ rights.
38
+
39
+ We protect your rights with two steps: (1) copyright the software, and
40
+ (2) offer you this license which gives you legal permission to copy,
41
+ distribute and/or modify the software.
42
+
43
+ Also, for each author's protection and ours, we want to make certain
44
+ that everyone understands that there is no warranty for this free
45
+ software. If the software is modified by someone else and passed on, we
46
+ want its recipients to know that what they have is not the original, so
47
+ that any problems introduced by others will not reflect on the original
48
+ authors' reputations.
49
+
50
+ Finally, any free program is threatened constantly by software
51
+ patents. We wish to avoid the danger that redistributors of a free
52
+ program will individually obtain patent licenses, in effect making the
53
+ program proprietary. To prevent this, we have made it clear that any
54
+ patent must be licensed for everyone's free use or not licensed at all.
55
+
56
+ The precise terms and conditions for copying, distribution and
57
+ modification follow.
58
+
59
+ GNU GENERAL PUBLIC LICENSE
60
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
61
+
62
+ 0. This License applies to any program or other work which contains
63
+ a notice placed by the copyright holder saying it may be distributed
64
+ under the terms of this General Public License. The "Program", below,
65
+ refers to any such program or work, and a "work based on the Program"
66
+ means either the Program or any derivative work under copyright law:
67
+ that is to say, a work containing the Program or a portion of it,
68
+ either verbatim or with modifications and/or translated into another
69
+ language. (Hereinafter, translation is included without limitation in
70
+ the term "modification".) Each licensee is addressed as "you".
71
+
72
+ Activities other than copying, distribution and modification are not
73
+ covered by this License; they are outside its scope. The act of
74
+ running the Program is not restricted, and the output from the Program
75
+ is covered only if its contents constitute a work based on the
76
+ Program (independent of having been made by running the Program).
77
+ Whether that is true depends on what the Program does.
78
+
79
+ 1. You may copy and distribute verbatim copies of the Program's
80
+ source code as you receive it, in any medium, provided that you
81
+ conspicuously and appropriately publish on each copy an appropriate
82
+ copyright notice and disclaimer of warranty; keep intact all the
83
+ notices that refer to this License and to the absence of any warranty;
84
+ and give any other recipients of the Program a copy of this License
85
+ along with the Program.
86
+
87
+ You may charge a fee for the physical act of transferring a copy, and
88
+ you may at your option offer warranty protection in exchange for a fee.
89
+
90
+ 2. You may modify your copy or copies of the Program or any portion
91
+ of it, thus forming a work based on the Program, and copy and
92
+ distribute such modifications or work under the terms of Section 1
93
+ above, provided that you also meet all of these conditions:
94
+
95
+ a) You must cause the modified files to carry prominent notices
96
+ stating that you changed the files and the date of any change.
97
+
98
+ b) You must cause any work that you distribute or publish, that in
99
+ whole or in part contains or is derived from the Program or any
100
+ part thereof, to be licensed as a whole at no charge to all third
101
+ parties under the terms of this License.
102
+
103
+ c) If the modified program normally reads commands interactively
104
+ when run, you must cause it, when started running for such
105
+ interactive use in the most ordinary way, to print or display an
106
+ announcement including an appropriate copyright notice and a
107
+ notice that there is no warranty (or else, saying that you provide
108
+ a warranty) and that users may redistribute the program under
109
+ these conditions, and telling the user how to view a copy of this
110
+ License. (Exception: if the Program itself is interactive but
111
+ does not normally print such an announcement, your work based on
112
+ the Program is not required to print an announcement.)
113
+
114
+ These requirements apply to the modified work as a whole. If
115
+ identifiable sections of that work are not derived from the Program,
116
+ and can be reasonably considered independent and separate works in
117
+ themselves, then this License, and its terms, do not apply to those
118
+ sections when you distribute them as separate works. But when you
119
+ distribute the same sections as part of a whole which is a work based
120
+ on the Program, the distribution of the whole must be on the terms of
121
+ this License, whose permissions for other licensees extend to the
122
+ entire whole, and thus to each and every part regardless of who wrote it.
123
+
124
+ Thus, it is not the intent of this section to claim rights or contest
125
+ your rights to work written entirely by you; rather, the intent is to
126
+ exercise the right to control the distribution of derivative or
127
+ collective works based on the Program.
128
+
129
+ In addition, mere aggregation of another work not based on the Program
130
+ with the Program (or with a work based on the Program) on a volume of
131
+ a storage or distribution medium does not bring the other work under
132
+ the scope of this License.
133
+
134
+ 3. You may copy and distribute the Program (or a work based on it,
135
+ under Section 2) in object code or executable form under the terms of
136
+ Sections 1 and 2 above provided that you also do one of the following:
137
+
138
+ a) Accompany it with the complete corresponding machine-readable
139
+ source code, which must be distributed under the terms of Sections
140
+ 1 and 2 above on a medium customarily used for software interchange; or,
141
+
142
+ b) Accompany it with a written offer, valid for at least three
143
+ years, to give any third party, for a charge no more than your
144
+ cost of physically performing source distribution, a complete
145
+ machine-readable copy of the corresponding source code, to be
146
+ distributed under the terms of Sections 1 and 2 above on a medium
147
+ customarily used for software interchange; or,
148
+
149
+ c) Accompany it with the information you received as to the offer
150
+ to distribute corresponding source code. (This alternative is
151
+ allowed only for noncommercial distribution and only if you
152
+ received the program in object code or executable form with such
153
+ an offer, in accord with Subsection b above.)
154
+
155
+ The source code for a work means the preferred form of the work for
156
+ making modifications to it. For an executable work, complete source
157
+ code means all the source code for all modules it contains, plus any
158
+ associated interface definition files, plus the scripts used to
159
+ control compilation and installation of the executable. However, as a
160
+ special exception, the source code distributed need not include
161
+ anything that is normally distributed (in either source or binary
162
+ form) with the major components (compiler, kernel, and so on) of the
163
+ operating system on which the executable runs, unless that component
164
+ itself accompanies the executable.
165
+
166
+ If distribution of executable or object code is made by offering
167
+ access to copy from a designated place, then offering equivalent
168
+ access to copy the source code from the same place counts as
169
+ distribution of the source code, even though third parties are not
170
+ compelled to copy the source along with the object code.
171
+
172
+ 4. You may not copy, modify, sublicense, or distribute the Program
173
+ except as expressly provided under this License. Any attempt
174
+ otherwise to copy, modify, sublicense or distribute the Program is
175
+ void, and will automatically terminate your rights under this License.
176
+ However, parties who have received copies, or rights, from you under
177
+ this License will not have their licenses terminated so long as such
178
+ parties remain in full compliance.
179
+
180
+ 5. You are not required to accept this License, since you have not
181
+ signed it. However, nothing else grants you permission to modify or
182
+ distribute the Program or its derivative works. These actions are
183
+ prohibited by law if you do not accept this License. Therefore, by
184
+ modifying or distributing the Program (or any work based on the
185
+ Program), you indicate your acceptance of this License to do so, and
186
+ all its terms and conditions for copying, distributing or modifying
187
+ the Program or works based on it.
188
+
189
+ 6. Each time you redistribute the Program (or any work based on the
190
+ Program), the recipient automatically receives a license from the
191
+ original licensor to copy, distribute or modify the Program subject to
192
+ these terms and conditions. You may not impose any further
193
+ restrictions on the recipients' exercise of the rights granted herein.
194
+ You are not responsible for enforcing compliance by third parties to
195
+ this License.
196
+
197
+ 7. If, as a consequence of a court judgment or allegation of patent
198
+ infringement or for any other reason (not limited to patent issues),
199
+ conditions are imposed on you (whether by court order, agreement or
200
+ otherwise) that contradict the conditions of this License, they do not
201
+ excuse you from the conditions of this License. If you cannot
202
+ distribute so as to satisfy simultaneously your obligations under this
203
+ License and any other pertinent obligations, then as a consequence you
204
+ may not distribute the Program at all. For example, if a patent
205
+ license would not permit royalty-free redistribution of the Program by
206
+ all those who receive copies directly or indirectly through you, then
207
+ the only way you could satisfy both it and this License would be to
208
+ refrain entirely from distribution of the Program.
209
+
210
+ If any portion of this section is held invalid or unenforceable under
211
+ any particular circumstance, the balance of the section is intended to
212
+ apply and the section as a whole is intended to apply in other
213
+ circumstances.
214
+
215
+ It is not the purpose of this section to induce you to infringe any
216
+ patents or other property right claims or to contest validity of any
217
+ such claims; this section has the sole purpose of protecting the
218
+ integrity of the free software distribution system, which is
219
+ implemented by public license practices. Many people have made
220
+ generous contributions to the wide range of software distributed
221
+ through that system in reliance on consistent application of that
222
+ system; it is up to the author/donor to decide if he or she is willing
223
+ to distribute software through any other system and a licensee cannot
224
+ impose that choice.
225
+
226
+ This section is intended to make thoroughly clear what is believed to
227
+ be a consequence of the rest of this License.
228
+
229
+ 8. If the distribution and/or use of the Program is restricted in
230
+ certain countries either by patents or by copyrighted interfaces, the
231
+ original copyright holder who places the Program under this License
232
+ may add an explicit geographical distribution limitation excluding
233
+ those countries, so that distribution is permitted only in or among
234
+ countries not thus excluded. In such case, this License incorporates
235
+ the limitation as if written in the body of this License.
236
+
237
+ 9. The Free Software Foundation may publish revised and/or new versions
238
+ of the General Public License from time to time. Such new versions will
239
+ be similar in spirit to the present version, but may differ in detail to
240
+ address new problems or concerns.
241
+
242
+ Each version is given a distinguishing version number. If the Program
243
+ specifies a version number of this License which applies to it and "any
244
+ later version", you have the option of following the terms and conditions
245
+ either of that version or of any later version published by the Free
246
+ Software Foundation. If the Program does not specify a version number of
247
+ this License, you may choose any version ever published by the Free Software
248
+ Foundation.
249
+
250
+ 10. If you wish to incorporate parts of the Program into other free
251
+ programs whose distribution conditions are different, write to the author
252
+ to ask for permission. For software which is copyrighted by the Free
253
+ Software Foundation, write to the Free Software Foundation; we sometimes
254
+ make exceptions for this. Our decision will be guided by the two goals
255
+ of preserving the free status of all derivatives of our free software and
256
+ of promoting the sharing and reuse of software generally.
257
+
258
+ NO WARRANTY
259
+
260
+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
261
+ FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
262
+ OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
263
+ PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
264
+ OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
265
+ MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
266
+ TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
267
+ PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
268
+ REPAIR OR CORRECTION.
269
+
270
+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
271
+ WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
272
+ REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
273
+ INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
274
+ OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
275
+ TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
276
+ YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
277
+ PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
278
+ POSSIBILITY OF SUCH DAMAGES.
279
+
280
+ END OF TERMS AND CONDITIONS
281
+
282
+ How to Apply These Terms to Your New Programs
283
+
284
+ If you develop a new program, and you want it to be of the greatest
285
+ possible use to the public, the best way to achieve this is to make it
286
+ free software which everyone can redistribute and change under these terms.
287
+
288
+ To do so, attach the following notices to the program. It is safest
289
+ to attach them to the start of each source file to most effectively
290
+ convey the exclusion of warranty; and each file should have at least
291
+ the "copyright" line and a pointer to where the full notice is found.
292
+
293
+ <one line to give the program's name and a brief idea of what it does.>
294
+ Copyright (C) <year> <name of author>
295
+
296
+ This program is free software; you can redistribute it and/or modify
297
+ it under the terms of the GNU General Public License as published by
298
+ the Free Software Foundation; either version 2 of the License, or
299
+ (at your option) any later version.
300
+
301
+ This program is distributed in the hope that it will be useful,
302
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
303
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
304
+ GNU General Public License for more details.
305
+
306
+ You should have received a copy of the GNU General Public License along
307
+ with this program; if not, write to the Free Software Foundation, Inc.,
308
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
309
+
310
+ Also add information on how to contact you by electronic and paper mail.
311
+
312
+ If the program is interactive, make it output a short notice like this
313
+ when it starts in an interactive mode:
314
+
315
+ Gnomovision version 69, Copyright (C) year name of author
316
+ Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
317
+ This is free software, and you are welcome to redistribute it
318
+ under certain conditions; type `show c' for details.
319
+
320
+ The hypothetical commands `show w' and `show c' should show the appropriate
321
+ parts of the General Public License. Of course, the commands you use may
322
+ be called something other than `show w' and `show c'; they could even be
323
+ mouse-clicks or menu items--whatever suits your program.
324
+
325
+ You should also get your employer (if you work as a programmer) or your
326
+ school, if any, to sign a "copyright disclaimer" for the program, if
327
+ necessary. Here is a sample; alter the names:
328
+
329
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the program
330
+ `Gnomovision' (which makes passes at compilers) written by James Hacker.
331
+
332
+ <signature of Ty Coon>, 1 April 1989
333
+ Ty Coon, President of Vice
334
+
335
+ This General Public License does not permit incorporating your program into
336
+ proprietary programs. If your program is a subroutine library, you may
337
+ consider it more useful to permit linking proprietary applications with the
338
+ library. If this is what you want to do, use the GNU Lesser General
339
+ Public License instead of this License.
data/Gemfile CHANGED
@@ -3,3 +3,5 @@
3
3
  source 'https://rubygems.org'
4
4
 
5
5
  gemspec
6
+
7
+ gem "codeclimate-test-reporter", group: :test, require: nil
@@ -1,26 +1,26 @@
1
- = ActiveRecord::Mutex
1
+ # ActiveRecord::Mutex
2
2
 
3
- == Description
3
+ ## Description
4
4
 
5
5
  This gem provides a Mutex that is based on ActiveRecord's database connection.
6
6
  (At the moment this only works for Mysql.) It can be used to synchronise
7
7
  ruby processes (also on different hosts) via the connected database.
8
8
 
9
- == Installation
9
+ ## Installation
10
10
 
11
11
  You can use rubygems to fetch the gem and install it for you:
12
12
 
13
- # gem install active_record_mutex
13
+ # gem install active_record_mutex
14
14
 
15
15
  You can also put this line into your Rails environment.rb file
16
16
 
17
- config.gem 'active_record_mutex'
17
+ config.gem 'active_record_mutex'
18
18
 
19
19
  and install the gem via
20
20
 
21
- $ rake gems:install
21
+ $ rake gems:install
22
22
 
23
- == Usage
23
+ ## Usage
24
24
 
25
25
  If you want to synchronize method calls to your model's methods you can easily
26
26
  do this by passing a mutex instance to ActiveRecord's synchronize class method.
@@ -36,6 +36,27 @@ This mutex instance will be named Foo like the ActiveRecord was named:
36
36
  If you want more control over the mutex and/or give it a special name you can
37
37
  create Mutex instance like this:
38
38
 
39
- my_mutex = ActiveRecord::Mutex::Mutex.new(:name => 'my_mutex')
39
+ my_mutex = ActiveRecord::Mutex::Mutex.new(:name => 'my_mutex')
40
40
 
41
41
  Now you can send all messages directly to the Mutex instance.
42
+
43
+ ## Changes
44
+
45
+ * 2014-12-12 Release 2.0.0
46
+ * 2014-12-12 Add license information
47
+ * 2014-12-09 Adapt to newer Rails versions' API
48
+
49
+ ## Download
50
+
51
+ The homepage of this library is located at
52
+
53
+ * https://github.com/flori/active_record_mutex
54
+
55
+ ## Author
56
+
57
+ [Florian Frank](mailto:flori@ping.de)
58
+
59
+ ## License
60
+
61
+ This software is licensed under the GPL (Version 2) license, see the file
62
+ COPYING.
data/Rakefile CHANGED
@@ -12,9 +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'
16
- readme 'README.rdoc'
15
+ ignore '.*.sw[pon]', 'pkg', 'Gemfile.lock', '.DS_Store', 'coverage'
16
+ readme 'README.md'
17
+ licenses << 'GPL-2'
17
18
 
18
- dependency 'mysql2', '~>0.3.0'
19
- dependency 'activerecord'
19
+ dependency 'mysql2', '~>0.3.0'
20
+ dependency 'activerecord'
21
+ development_dependency 'test-unit', '~>3.0'
22
+ development_dependency 'byebug'
23
+ development_dependency 'simplecov'
20
24
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.1
1
+ 2.0.0
@@ -1,38 +1,48 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: active_record_mutex 1.0.1 ruby lib
2
+ # stub: active_record_mutex 2.0.0 ruby lib
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "active_record_mutex"
6
- s.version = "1.0.1"
6
+ s.version = "2.0.0"
7
7
 
8
8
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
9
+ s.require_paths = ["lib"]
9
10
  s.authors = ["Florian Frank"]
10
- s.date = "2013-11-18"
11
+ s.date = "2014-12-12"
11
12
  s.description = "Mutex that can be used to synchronise ruby processes via an ActiveRecord datababase connection. (Only Mysql is supported at the moment.)"
12
13
  s.email = "flori@ping.de"
13
- s.extra_rdoc_files = ["README.rdoc", "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"]
14
- s.files = [".gitignore", "CHANGES", "Gemfile", "README.rdoc", "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/mutex_test.rb"]
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
16
  s.homepage = "http://github.com/flori/active_record_mutex"
16
- s.rdoc_options = ["--title", "ActiveRecordMutex - Implementation of a Mutex for Active Record", "--main", "README.rdoc"]
17
- s.require_paths = ["lib"]
18
- s.rubygems_version = "2.1.11"
17
+ s.licenses = ["GPL-2"]
18
+ s.rdoc_options = ["--title", "ActiveRecordMutex - Implementation of a Mutex for Active Record", "--main", "README.md"]
19
+ s.rubygems_version = "2.4.4"
19
20
  s.summary = "Implementation of a Mutex for Active Record"
20
- s.test_files = ["test/mutex_test.rb"]
21
+ s.test_files = ["test/database_mutex_test.rb", "test/test_helper.rb"]
21
22
 
22
23
  if s.respond_to? :specification_version then
23
24
  s.specification_version = 4
24
25
 
25
26
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
26
27
  s.add_development_dependency(%q<gem_hadar>, ["~> 0.3.2"])
28
+ s.add_development_dependency(%q<test-unit>, ["~> 3.0"])
29
+ s.add_development_dependency(%q<byebug>, [">= 0"])
30
+ s.add_development_dependency(%q<simplecov>, [">= 0"])
27
31
  s.add_runtime_dependency(%q<mysql2>, ["~> 0.3.0"])
28
32
  s.add_runtime_dependency(%q<activerecord>, [">= 0"])
29
33
  else
30
34
  s.add_dependency(%q<gem_hadar>, ["~> 0.3.2"])
35
+ s.add_dependency(%q<test-unit>, ["~> 3.0"])
36
+ s.add_dependency(%q<byebug>, [">= 0"])
37
+ s.add_dependency(%q<simplecov>, [">= 0"])
31
38
  s.add_dependency(%q<mysql2>, ["~> 0.3.0"])
32
39
  s.add_dependency(%q<activerecord>, [">= 0"])
33
40
  end
34
41
  else
35
42
  s.add_dependency(%q<gem_hadar>, ["~> 0.3.2"])
43
+ s.add_dependency(%q<test-unit>, ["~> 3.0"])
44
+ s.add_dependency(%q<byebug>, [">= 0"])
45
+ s.add_dependency(%q<simplecov>, [">= 0"])
36
46
  s.add_dependency(%q<mysql2>, ["~> 0.3.0"])
37
47
  s.add_dependency(%q<activerecord>, [">= 0"])
38
48
  end
@@ -17,12 +17,19 @@ module ActiveRecord
17
17
  # moment and lock was called again.
18
18
  class MutexLocked < MutexError; end
19
19
 
20
+ class MutexInvalidState < MutexError; end
21
+
20
22
  def self.included(modul)
21
23
  modul.instance_eval do
22
24
  extend ClassMethods
23
25
  end
24
26
  end
25
27
 
28
+ # XXX
29
+ def self.for(name)
30
+ Implementation.new(:name => name)
31
+ end
32
+
26
33
  module ClassMethods
27
34
  # Returns a mutex instance for this ActiveRecord subclass.
28
35
  def mutex
@@ -32,7 +39,11 @@ module ActiveRecord
32
39
 
33
40
  # Returns a mutex instance for this ActiveRecord instance.
34
41
  def mutex
35
- @mutex ||= Implementation.new(:name => self.class.name)
42
+ if persisted?
43
+ @mutex ||= Implementation.new(:name => "#{id}@#{self.class.name}")
44
+ else
45
+ raise MutexInvalidState, "instance #{inspect} not persisted"
46
+ end
36
47
  end
37
48
  end
38
49
  end
@@ -25,12 +25,12 @@ module ActiveRecord
25
25
  # lock couldn't be aquired during that time.
26
26
  def synchronize(opts = {})
27
27
  locked_before = aquired_lock?
28
- lock opts
28
+ locked = lock(opts) or return
29
29
  yield
30
30
  rescue ActiveRecord::DatabaseMutex::MutexLocked
31
31
  return nil
32
32
  ensure
33
- locked_before or unlock
33
+ locked_before or locked && unlock
34
34
  end
35
35
 
36
36
  # Locks the mutex and returns true if successful. If the mutex is
@@ -39,11 +39,17 @@ module ActiveRecord
39
39
  # seconds. If the :timeout option wasn't given, this method blocks until
40
40
  # the lock could be aquired.
41
41
  def lock(opts = {})
42
- if opts[:timeout]
42
+ if opts[:nonblock] # XXX document
43
+ begin
44
+ lock_with_timeout :timeout => 0
45
+ rescue MutexLocked
46
+ end
47
+ elsif opts[:timeout]
43
48
  lock_with_timeout opts
44
49
  else
50
+ spin_timeout = opts[:spin_timeout] || 1 # XXX document
45
51
  begin
46
- lock_with_timeout :timeout => 1
52
+ lock_with_timeout :timeout => spin_timeout
47
53
  rescue MutexLocked
48
54
  retry
49
55
  end
@@ -53,15 +59,23 @@ module ActiveRecord
53
59
  # Unlocks the mutex and returns true if successful. Otherwise this method
54
60
  # raises a MutexLocked exception.
55
61
  def unlock(*)
56
- case query("SELECT RELEASE_LOCK(#{ActiveRecord::Base.quote_value(name)})")
62
+ case query("SELECT RELEASE_LOCK(#{quote_value(name)})")
57
63
  when 1 then true
58
64
  when 0, nil then raise MutexUnlockFailed, "unlocking of mutex '#{name}' failed"
59
65
  end
60
66
  end
61
67
 
68
+ # XXX
69
+ def unlock?(*a)
70
+ unlock(*a)
71
+ self
72
+ rescue MutexUnlockFailed
73
+ nil
74
+ end
75
+
62
76
  # Returns true if this mutex is unlocked at the moment.
63
77
  def unlocked?
64
- query("SELECT IS_FREE_LOCK(#{ActiveRecord::Base.quote_value(name)})") == 1
78
+ query("SELECT IS_FREE_LOCK(#{quote_value(name)})") == 1
65
79
  end
66
80
 
67
81
  # Returns true if this mutex is locked at the moment.
@@ -71,7 +85,7 @@ module ActiveRecord
71
85
 
72
86
  # Returns true if this mutex is locked by this database connection.
73
87
  def aquired_lock?
74
- query("SELECT CONNECTION_ID() = IS_USED_LOCK(#{ActiveRecord::Base.quote_value(name)})") == 1
88
+ query("SELECT CONNECTION_ID() = IS_USED_LOCK(#{quote_value(name)})") == 1
75
89
  end
76
90
 
77
91
  # Returns true if this mutex is not locked by this database connection.
@@ -88,9 +102,13 @@ module ActiveRecord
88
102
 
89
103
  private
90
104
 
105
+ def quote_value(value)
106
+ ActiveRecord::Base.connection.quote(value)
107
+ end
108
+
91
109
  def lock_with_timeout(opts = {})
92
110
  timeout = opts[:timeout] || 1
93
- case query("SELECT GET_LOCK(#{ActiveRecord::Base.quote_value(name)}, #{timeout})")
111
+ case query("SELECT GET_LOCK(#{quote_value(name)}, #{timeout})")
94
112
  when 1 then true
95
113
  when 0 then raise MutexLocked, "mutex '#{name}' is already locked"
96
114
  end
@@ -1,6 +1,6 @@
1
1
  module ActiveRecord::DatabaseMutex
2
2
  # ActiveRecord::DatabaseMutex version
3
- VERSION = '1.0.1'
3
+ VERSION = '2.0.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:
@@ -1,19 +1,6 @@
1
- require 'test/unit'
2
- require 'rubygems'
1
+ require 'test_helper'
3
2
 
4
- require 'active_record'
5
- $:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
6
- require 'active_record/database_mutex'
7
-
8
- ActiveRecord::Base.establish_connection(
9
- :adapter => "mysql2",
10
- :database => ENV['DATABASE'] || "test",
11
- :username => ENV['USER'],
12
- :password => ENV['PASSWORD'],
13
- :host => ENV['HOST'] || 'localhost'
14
- )
15
-
16
- class MutexTest < Test::Unit::TestCase
3
+ class DatabaseMutexTest < Test::Unit::TestCase
17
4
  include ActiveRecord::DatabaseMutex
18
5
 
19
6
  class Foo < ActiveRecord::Base; end
@@ -30,13 +17,26 @@ class MutexTest < Test::Unit::TestCase
30
17
  end
31
18
  end
32
19
 
33
- def test_exported_methods
20
+ def test_class_methods
34
21
  mutex = Foo.mutex
35
22
  assert_kind_of ActiveRecord::DatabaseMutex::Implementation, mutex
36
23
  assert_equal mutex.name, Foo.name
37
- mutex = Foo.new.mutex
24
+ end
25
+
26
+ def test_instance_method
27
+ instance = Foo.new
28
+ assert_raises(ActiveRecord::DatabaseMutex::MutexInvalidState) do
29
+ instance.mutex
30
+ end
31
+ assert_equal true, instance.save
32
+ mutex = instance.mutex
33
+ assert_kind_of ActiveRecord::DatabaseMutex::Implementation, mutex
34
+ assert_equal mutex.name, "#{instance.id}@#{Foo.name}"
35
+ end
36
+
37
+ def test_factory_method_for
38
+ mutex = ActiveRecord::DatabaseMutex.for('some_name')
38
39
  assert_kind_of ActiveRecord::DatabaseMutex::Implementation, mutex
39
- assert_equal mutex.name, Foo.name
40
40
  end
41
41
 
42
42
  def test_create
@@ -0,0 +1,18 @@
1
+ if ENV.key?('CODECLIMATE_REPO_TOKEN')
2
+ require "codeclimate-test-reporter"
3
+ CodeClimate::TestReporter.start
4
+ end
5
+
6
+ $:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
7
+ require 'active_record'
8
+ require 'active_record/database_mutex'
9
+
10
+ ActiveRecord::Base.establish_connection(
11
+ :adapter => "mysql2",
12
+ :database => ENV['DATABASE'] || "test",
13
+ :username => ENV['USER'],
14
+ :password => ENV['PASSWORD'],
15
+ :host => ENV['HOST'] || 'localhost'
16
+ )
17
+ require 'test/unit'
18
+ require 'byebug'
metadata CHANGED
@@ -1,55 +1,97 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_record_mutex
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 2.0.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: 2013-11-18 00:00:00.000000000 Z
11
+ date: 2014-12-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gem_hadar
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: 0.3.2
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
26
  version: 0.3.2
27
+ - !ruby/object:Gem::Dependency
28
+ name: test-unit
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: byebug
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: simplecov
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
27
69
  - !ruby/object:Gem::Dependency
28
70
  name: mysql2
29
71
  requirement: !ruby/object:Gem::Requirement
30
72
  requirements:
31
- - - ~>
73
+ - - "~>"
32
74
  - !ruby/object:Gem::Version
33
75
  version: 0.3.0
34
76
  type: :runtime
35
77
  prerelease: false
36
78
  version_requirements: !ruby/object:Gem::Requirement
37
79
  requirements:
38
- - - ~>
80
+ - - "~>"
39
81
  - !ruby/object:Gem::Version
40
82
  version: 0.3.0
41
83
  - !ruby/object:Gem::Dependency
42
84
  name: activerecord
43
85
  requirement: !ruby/object:Gem::Requirement
44
86
  requirements:
45
- - - '>='
87
+ - - ">="
46
88
  - !ruby/object:Gem::Version
47
89
  version: '0'
48
90
  type: :runtime
49
91
  prerelease: false
50
92
  version_requirements: !ruby/object:Gem::Requirement
51
93
  requirements:
52
- - - '>='
94
+ - - ">="
53
95
  - !ruby/object:Gem::Version
54
96
  version: '0'
55
97
  description: Mutex that can be used to synchronise ruby processes via an ActiveRecord
@@ -58,17 +100,19 @@ email: flori@ping.de
58
100
  executables: []
59
101
  extensions: []
60
102
  extra_rdoc_files:
61
- - README.rdoc
103
+ - README.md
62
104
  - lib/active_record/database_mutex.rb
63
105
  - lib/active_record/database_mutex/implementation.rb
64
106
  - lib/active_record/database_mutex/version.rb
65
107
  - lib/active_record/mutex.rb
66
108
  - lib/active_record_mutex.rb
67
109
  files:
68
- - .gitignore
110
+ - ".gitignore"
111
+ - ".travis.yml"
69
112
  - CHANGES
113
+ - COPYING
70
114
  - Gemfile
71
- - README.rdoc
115
+ - README.md
72
116
  - Rakefile
73
117
  - VERSION
74
118
  - active_record_mutex.gemspec
@@ -77,33 +121,36 @@ files:
77
121
  - lib/active_record/database_mutex/version.rb
78
122
  - lib/active_record/mutex.rb
79
123
  - lib/active_record_mutex.rb
80
- - test/mutex_test.rb
124
+ - test/database_mutex_test.rb
125
+ - test/test_helper.rb
81
126
  homepage: http://github.com/flori/active_record_mutex
82
- licenses: []
127
+ licenses:
128
+ - GPL-2
83
129
  metadata: {}
84
130
  post_install_message:
85
131
  rdoc_options:
86
- - --title
132
+ - "--title"
87
133
  - ActiveRecordMutex - Implementation of a Mutex for Active Record
88
- - --main
89
- - README.rdoc
134
+ - "--main"
135
+ - README.md
90
136
  require_paths:
91
137
  - lib
92
138
  required_ruby_version: !ruby/object:Gem::Requirement
93
139
  requirements:
94
- - - '>='
140
+ - - ">="
95
141
  - !ruby/object:Gem::Version
96
142
  version: '0'
97
143
  required_rubygems_version: !ruby/object:Gem::Requirement
98
144
  requirements:
99
- - - '>='
145
+ - - ">="
100
146
  - !ruby/object:Gem::Version
101
147
  version: '0'
102
148
  requirements: []
103
149
  rubyforge_project:
104
- rubygems_version: 2.1.11
150
+ rubygems_version: 2.4.4
105
151
  signing_key:
106
152
  specification_version: 4
107
153
  summary: Implementation of a Mutex for Active Record
108
154
  test_files:
109
- - test/mutex_test.rb
155
+ - test/database_mutex_test.rb
156
+ - test/test_helper.rb