highlander 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +2 -0
- data/MANIFEST +7 -0
- data/README +45 -0
- data/Rakefile +26 -0
- data/highlander.gemspec +25 -0
- data/lib/highlander.rb +19 -0
- data/test/test_highlander.rb +19 -0
- metadata +90 -0
data/CHANGES
ADDED
data/MANIFEST
ADDED
data/README
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
= Description
|
2
|
+
A gem that ensures only one instance of your main script is running.
|
3
|
+
In short, there can be only one.
|
4
|
+
|
5
|
+
= Installation
|
6
|
+
gem install highlander
|
7
|
+
|
8
|
+
= Synopsis
|
9
|
+
require 'highlander'
|
10
|
+
# Your code here
|
11
|
+
|
12
|
+
# Meanwhile, back on the command line...
|
13
|
+
|
14
|
+
# First attempt, works. Assume it's running in the background.
|
15
|
+
ruby your_script.rb
|
16
|
+
|
17
|
+
# Second attempt while the first instance is still running, fails.
|
18
|
+
ruby your_script.rb # => RuntimeError
|
19
|
+
|
20
|
+
= Notes
|
21
|
+
Simply requiring the highlander gem ensures that only one instance
|
22
|
+
of that script cannot be started again. If you try to start it again
|
23
|
+
it will raise a RuntimeError.
|
24
|
+
|
25
|
+
= Known Issues
|
26
|
+
If you start your program, modify it while its running, and run it again
|
27
|
+
then this library will not work.
|
28
|
+
|
29
|
+
= Acknowledgements
|
30
|
+
Ara Howard for ideas.
|
31
|
+
|
32
|
+
= License
|
33
|
+
Artistic 2.0
|
34
|
+
|
35
|
+
= Copyright
|
36
|
+
(C) 2010 Daniel J. Berger
|
37
|
+
All Rights Reserved.
|
38
|
+
|
39
|
+
== Warranty
|
40
|
+
This package is provided "as is" and without any express or
|
41
|
+
implied warranties, including, without limitation, the implied
|
42
|
+
warranties of merchantability and fitness for a particular purpose.
|
43
|
+
|
44
|
+
= Author
|
45
|
+
Daniel Berger
|
data/Rakefile
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/clean'
|
3
|
+
require 'rake/testtask'
|
4
|
+
|
5
|
+
CLEAN.include("**/*.gem", "**/*.rbc")
|
6
|
+
|
7
|
+
namespace 'gem' do
|
8
|
+
desc 'Create the highlander gem'
|
9
|
+
task :create => [:clean] do
|
10
|
+
spec = eval(IO.read('highlander.gemspec'))
|
11
|
+
Gem::Builder.new(spec).build
|
12
|
+
end
|
13
|
+
|
14
|
+
desc 'Install the highlander gem'
|
15
|
+
task :install => [:create] do
|
16
|
+
file = Dir["*.gem"].first
|
17
|
+
sh "gem install #{file}"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
Rake::TestTask.new do |t|
|
22
|
+
t.verbose = true
|
23
|
+
t.warning = true
|
24
|
+
end
|
25
|
+
|
26
|
+
task :default => :test
|
data/highlander.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
|
3
|
+
Gem::Specification.new do |gem|
|
4
|
+
gem.name = 'highlander'
|
5
|
+
gem.version = '0.1.0'
|
6
|
+
gem.license = 'Artistic 2.0'
|
7
|
+
gem.author = 'Daniel J. Berger'
|
8
|
+
gem.email = 'djberg96@gmail.com'
|
9
|
+
gem.homepage = 'http://www.rubyforge.org/projects/shards'
|
10
|
+
gem.summary = 'There can be only one! Process, that is.'
|
11
|
+
gem.test_files = Dir['test/test*']
|
12
|
+
gem.has_rdoc = true
|
13
|
+
gem.files = Dir['**/*'].reject{ |f| f.include?('git') }
|
14
|
+
|
15
|
+
gem.rubyforge_project = 'shards'
|
16
|
+
gem.extra_rdoc_files = ['README', 'CHANGES', 'MANIFEST']
|
17
|
+
|
18
|
+
gem.description = <<-EOF
|
19
|
+
The highlander gem ensures that only once instance of the current
|
20
|
+
process is running. If you try to run the same Ruby program again
|
21
|
+
it will raise a RuntimeError instead.
|
22
|
+
EOF
|
23
|
+
|
24
|
+
gem.add_development_dependency('test-unit', '>= 2.1.1')
|
25
|
+
end
|
data/lib/highlander.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
module Highlander
|
2
|
+
# The version of the highlander library
|
3
|
+
VERSION = '0.1.0'
|
4
|
+
|
5
|
+
BEGIN{
|
6
|
+
unless $0 == 'irb'
|
7
|
+
program = File.expand_path($0)
|
8
|
+
DATA = File.open(program) unless defined?(DATA)
|
9
|
+
status = DATA.flock(File::LOCK_EX | File::LOCK_NB)
|
10
|
+
|
11
|
+
if status != 0
|
12
|
+
raise RuntimeError, "Program '#{program}' already running"
|
13
|
+
exit! # In case of rescue, forcibly bail
|
14
|
+
end
|
15
|
+
end
|
16
|
+
}
|
17
|
+
end
|
18
|
+
|
19
|
+
include Highlander
|
@@ -0,0 +1,19 @@
|
|
1
|
+
#######################################################################
|
2
|
+
# test_highlander.rb
|
3
|
+
#
|
4
|
+
# Test suite for the highlander gem.
|
5
|
+
#######################################################################
|
6
|
+
require 'test/unit'
|
7
|
+
require 'highlander'
|
8
|
+
|
9
|
+
class TC_Highlander < Test::Unit::TestCase
|
10
|
+
def setup
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_version
|
14
|
+
assert_equal("0.1.0", Highlander::VERSION)
|
15
|
+
end
|
16
|
+
|
17
|
+
def teardown
|
18
|
+
end
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: highlander
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Daniel J. Berger
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-12-12 00:00:00 -07:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: test-unit
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 9
|
30
|
+
segments:
|
31
|
+
- 2
|
32
|
+
- 1
|
33
|
+
- 1
|
34
|
+
version: 2.1.1
|
35
|
+
type: :development
|
36
|
+
version_requirements: *id001
|
37
|
+
description: " The highlander gem ensures that only once instance of the current\n process is running. If you try to run the same Ruby program again\n it will raise a RuntimeError instead.\n"
|
38
|
+
email: djberg96@gmail.com
|
39
|
+
executables: []
|
40
|
+
|
41
|
+
extensions: []
|
42
|
+
|
43
|
+
extra_rdoc_files:
|
44
|
+
- README
|
45
|
+
- CHANGES
|
46
|
+
- MANIFEST
|
47
|
+
files:
|
48
|
+
- CHANGES
|
49
|
+
- highlander.gemspec
|
50
|
+
- lib/highlander.rb
|
51
|
+
- MANIFEST
|
52
|
+
- Rakefile
|
53
|
+
- README
|
54
|
+
- test/test_highlander.rb
|
55
|
+
has_rdoc: true
|
56
|
+
homepage: http://www.rubyforge.org/projects/shards
|
57
|
+
licenses:
|
58
|
+
- Artistic 2.0
|
59
|
+
post_install_message:
|
60
|
+
rdoc_options: []
|
61
|
+
|
62
|
+
require_paths:
|
63
|
+
- lib
|
64
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
hash: 3
|
70
|
+
segments:
|
71
|
+
- 0
|
72
|
+
version: "0"
|
73
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
hash: 3
|
79
|
+
segments:
|
80
|
+
- 0
|
81
|
+
version: "0"
|
82
|
+
requirements: []
|
83
|
+
|
84
|
+
rubyforge_project: shards
|
85
|
+
rubygems_version: 1.3.7
|
86
|
+
signing_key:
|
87
|
+
specification_version: 3
|
88
|
+
summary: There can be only one! Process, that is.
|
89
|
+
test_files:
|
90
|
+
- test/test_highlander.rb
|