kissifer-utils 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +5 -0
- data/LICENSE +20 -0
- data/README.rdoc +9 -0
- data/Rakefile +49 -0
- data/VERSION +1 -0
- data/lib/utils.rb +3 -0
- data/lib/utils/flock_mutex.rb +19 -0
- data/spec/flock_mutex_spec.rb +60 -0
- data/spec/spec.opts +2 -0
- data/spec/spec_helper.rb +9 -0
- data/utils.gemspec +48 -0
- metadata +66 -0
data/.document
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 kissifer
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
= utils
|
2
|
+
|
3
|
+
Library of potentially useful stuff that I haven't (yet) found elsewhere
|
4
|
+
Contains:
|
5
|
+
utils/flock - simple cross-process Mutex-like functionality based on FLOCK. Not the full Mutex API.
|
6
|
+
|
7
|
+
== Copyright
|
8
|
+
|
9
|
+
Copyright (c) 2009 kissifer. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "utils"
|
8
|
+
gem.summary = %Q{Library of potentially useful stuff that I haven't (yet) found elsewhere}
|
9
|
+
gem.email = "tierneydrchris@gmail.com"
|
10
|
+
gem.homepage = "http://github.com/kissifer/utils"
|
11
|
+
gem.authors = ["kissifer"]
|
12
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
13
|
+
end
|
14
|
+
|
15
|
+
rescue LoadError
|
16
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
17
|
+
end
|
18
|
+
|
19
|
+
require 'spec/rake/spectask'
|
20
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
21
|
+
spec.libs << 'lib' << 'spec'
|
22
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
23
|
+
spec.spec_opts = ['--options spec/spec.opts']
|
24
|
+
end
|
25
|
+
|
26
|
+
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
27
|
+
spec.libs << 'lib' << 'spec'
|
28
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
29
|
+
spec.rcov = true
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
task :default => :spec
|
34
|
+
|
35
|
+
require 'rake/rdoctask'
|
36
|
+
Rake::RDocTask.new do |rdoc|
|
37
|
+
if File.exist?('VERSION.yml')
|
38
|
+
config = YAML.load(File.read('VERSION.yml'))
|
39
|
+
version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
|
40
|
+
else
|
41
|
+
version = ""
|
42
|
+
end
|
43
|
+
|
44
|
+
rdoc.rdoc_dir = 'rdoc'
|
45
|
+
rdoc.title = "utils #{version}"
|
46
|
+
rdoc.rdoc_files.include('README*')
|
47
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
48
|
+
end
|
49
|
+
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
data/lib/utils.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
module Utils
|
2
|
+
class FlockMutex
|
3
|
+
def initialize(filename)
|
4
|
+
@filename = filename
|
5
|
+
FileUtils.touch(@filename)
|
6
|
+
end
|
7
|
+
|
8
|
+
def synchronize
|
9
|
+
open(@filename, 'w+') do |f|
|
10
|
+
f.flock(File::LOCK_EX)
|
11
|
+
begin
|
12
|
+
yield
|
13
|
+
ensure
|
14
|
+
f.flock(File::LOCK_UN)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "Utils::FlockMutex" do
|
4
|
+
before(:each) do
|
5
|
+
FileUtils.rm_f(".mylockfile")
|
6
|
+
end
|
7
|
+
|
8
|
+
context "(on instantiation)" do
|
9
|
+
it "should not accept an empty initialiser" do
|
10
|
+
lambda{Utils::FlockMutex.new}.should raise_error
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should accept a filename as initialiser" do
|
14
|
+
lambda{Utils::FlockMutex.new(".mylockfile")}.should_not raise_error
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should create a specified file if not present" do
|
18
|
+
lambda{Utils::FlockMutex.new(".mylockfile")}.should_not raise_error
|
19
|
+
File.exists?(".mylockfile").should be_true
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should not complain if the specified file is present" do
|
23
|
+
FileUtils.touch(".mylockfile")
|
24
|
+
lambda{Utils::FlockMutex.new(".mylockfile")}.should_not raise_error
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should not complain if the specified file is present and is locked" do
|
28
|
+
FileUtils.touch(".mylockfile")
|
29
|
+
File.open('.mylockfile', 'w+') do |f|
|
30
|
+
f.flock(File::LOCK_EX)
|
31
|
+
begin
|
32
|
+
lambda{Utils::FlockMutex.new(".mylockfile")}.should_not raise_error
|
33
|
+
ensure
|
34
|
+
f.flock(File::LOCK_UN)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
context "(an instance)" do
|
41
|
+
it "should allow locking (against another process) around a code block" do
|
42
|
+
# TODO: this is a crap test. Rewrite (and split it up).
|
43
|
+
lock = Utils::FlockMutex.new(".mylockfile")
|
44
|
+
lock.synchronize do
|
45
|
+
IO.popen("-","w+") do |io|
|
46
|
+
File.open('.mylockfile', 'w+') do |f|
|
47
|
+
f.flock(File::LOCK_EX | File::LOCK_NB)
|
48
|
+
end
|
49
|
+
end.should be_false
|
50
|
+
end
|
51
|
+
|
52
|
+
IO.popen("-","w+") do |io|
|
53
|
+
File.open('.mylockfile', 'w+') do |f|
|
54
|
+
f.flock(File::LOCK_EX | File::LOCK_NB)
|
55
|
+
end
|
56
|
+
end.should be_true
|
57
|
+
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
data/spec/spec.opts
ADDED
data/spec/spec_helper.rb
ADDED
data/utils.gemspec
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{utils}
|
5
|
+
s.version = "0.0.1"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["kissifer"]
|
9
|
+
s.date = %q{2009-05-22}
|
10
|
+
s.email = %q{tierneydrchris@gmail.com}
|
11
|
+
s.extra_rdoc_files = [
|
12
|
+
"LICENSE",
|
13
|
+
"README.rdoc"
|
14
|
+
]
|
15
|
+
s.files = [
|
16
|
+
".document",
|
17
|
+
".gitignore",
|
18
|
+
"LICENSE",
|
19
|
+
"README.rdoc",
|
20
|
+
"Rakefile",
|
21
|
+
"VERSION",
|
22
|
+
"lib/utils.rb",
|
23
|
+
"lib/utils/flock_mutex.rb",
|
24
|
+
"spec/flock_mutex_spec.rb",
|
25
|
+
"spec/spec.opts",
|
26
|
+
"spec/spec_helper.rb",
|
27
|
+
"utils.gemspec"
|
28
|
+
]
|
29
|
+
s.homepage = %q{http://github.com/kissifer/utils}
|
30
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
31
|
+
s.require_paths = ["lib"]
|
32
|
+
s.rubygems_version = %q{1.3.3}
|
33
|
+
s.summary = %q{Library of potentially useful stuff that I haven't (yet) found elsewhere}
|
34
|
+
s.test_files = [
|
35
|
+
"spec/flock_mutex_spec.rb",
|
36
|
+
"spec/spec_helper.rb"
|
37
|
+
]
|
38
|
+
|
39
|
+
if s.respond_to? :specification_version then
|
40
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
41
|
+
s.specification_version = 3
|
42
|
+
|
43
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
44
|
+
else
|
45
|
+
end
|
46
|
+
else
|
47
|
+
end
|
48
|
+
end
|
metadata
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: kissifer-utils
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- kissifer
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-05-22 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description:
|
17
|
+
email: tierneydrchris@gmail.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- LICENSE
|
24
|
+
- README.rdoc
|
25
|
+
files:
|
26
|
+
- .document
|
27
|
+
- .gitignore
|
28
|
+
- LICENSE
|
29
|
+
- README.rdoc
|
30
|
+
- Rakefile
|
31
|
+
- VERSION
|
32
|
+
- lib/utils.rb
|
33
|
+
- lib/utils/flock_mutex.rb
|
34
|
+
- spec/flock_mutex_spec.rb
|
35
|
+
- spec/spec.opts
|
36
|
+
- spec/spec_helper.rb
|
37
|
+
- utils.gemspec
|
38
|
+
has_rdoc: false
|
39
|
+
homepage: http://github.com/kissifer/utils
|
40
|
+
post_install_message:
|
41
|
+
rdoc_options:
|
42
|
+
- --charset=UTF-8
|
43
|
+
require_paths:
|
44
|
+
- lib
|
45
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: "0"
|
50
|
+
version:
|
51
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: "0"
|
56
|
+
version:
|
57
|
+
requirements: []
|
58
|
+
|
59
|
+
rubyforge_project:
|
60
|
+
rubygems_version: 1.2.0
|
61
|
+
signing_key:
|
62
|
+
specification_version: 3
|
63
|
+
summary: Library of potentially useful stuff that I haven't (yet) found elsewhere
|
64
|
+
test_files:
|
65
|
+
- spec/flock_mutex_spec.rb
|
66
|
+
- spec/spec_helper.rb
|