lockit 0.0.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,16 @@
1
+ # rcov generated
2
+ coverage
3
+
4
+ # rdoc generated
5
+ rdoc
6
+
7
+ # yard generated
8
+ doc
9
+ .yardoc
10
+
11
+ # bundler
12
+ .bundle
13
+
14
+ # jeweler generated
15
+ pkg
16
+ Gemfile.lock
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm use ree@lockit --create
data/Gemfile CHANGED
@@ -1,13 +1,3 @@
1
1
  source "http://rubygems.org"
2
- # Add dependencies required to use your gem here.
3
- # Example:
4
- # gem "activesupport", ">= 2.3.5"
5
2
 
6
- # Add dependencies to develop your gem here.
7
- # Include everything needed to run rake, tests, features, etc.
8
- group :development do
9
- gem "shoulda", ">= 0"
10
- gem "bundler", "~> 1.0.0"
11
- gem "jeweler", "~> 1.5.1"
12
- gem "rcov", ">= 0"
13
- end
3
+ gemspec
data/Gemfile.lock CHANGED
@@ -1,20 +1,31 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ lockit (0.1.1)
5
+
1
6
  GEM
2
7
  remote: http://rubygems.org/
3
8
  specs:
4
- git (1.2.5)
5
- jeweler (1.5.1)
6
- bundler (~> 1.0.0)
7
- git (>= 1.2.5)
8
- rake
9
+ diff-lcs (1.1.2)
9
10
  rake (0.8.7)
10
11
  rcov (0.9.9)
11
- shoulda (2.11.3)
12
+ rspec (2.6.0)
13
+ rspec-core (~> 2.6.0)
14
+ rspec-expectations (~> 2.6.0)
15
+ rspec-mocks (~> 2.6.0)
16
+ rspec-core (2.6.4)
17
+ rspec-expectations (2.6.0)
18
+ diff-lcs (~> 1.1.2)
19
+ rspec-mocks (2.6.0)
20
+ yard (0.7.1)
12
21
 
13
22
  PLATFORMS
14
23
  ruby
15
24
 
16
25
  DEPENDENCIES
17
- bundler (~> 1.0.0)
18
- jeweler (~> 1.5.1)
26
+ bundler
27
+ lockit!
28
+ rake
19
29
  rcov
20
- shoulda
30
+ rspec
31
+ yard
data/LICENSE.txt CHANGED
@@ -1,20 +1,12 @@
1
- Copyright (c) 2010 Chris Beer
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.
1
+ ###########################################################################
2
+ # Licensed under the Apache License, Version 2.0 (the "License");
3
+ # you may not use this file except in compliance with the License.
4
+ # You may obtain a copy of the License at
5
+ #
6
+ # http://www.apache.org/licenses/LICENSE-2.0
7
+ #
8
+ # Unless required by applicable law or agreed to in writing, software
9
+ # distributed under the License is distributed on an "AS IS" BASIS,
10
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ # See the License for the specific language governing permissions and
12
+ # limitations under the License.
data/Rakefile CHANGED
@@ -8,45 +8,40 @@ rescue Bundler::BundlerError => e
8
8
  exit e.status_code
9
9
  end
10
10
  require 'rake'
11
+ require 'rspec'
12
+ require 'rspec/core/rake_task'
11
13
 
12
- require 'jeweler'
13
- Jeweler::Tasks.new do |gem|
14
- # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
15
- gem.name = "lockit"
16
- gem.homepage = "http://github.com/cbeer/lockit"
17
- gem.license = "MIT"
18
- gem.summary = "A ruby implementation of LockIt: A Simple File-based Convention for Resource Locking"
19
- gem.email = "chris@cbeer.info"
20
- gem.authors = ["Chris Beer"]
21
- # Include your dependencies below. Runtime dependencies are required when using your gem,
22
- # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
23
- # gem.add_runtime_dependency 'jabber4r', '> 0.1'
24
- # gem.add_development_dependency 'rspec', '> 1.2.3'
14
+ RSpec::Core::RakeTask.new() do |t|
15
+ t.pattern = "./spec/*_spec.rb" # don't need this, it's default.
16
+ t.rcov = true
17
+ t.rcov_opts = ['--exclude', 'spec', '--exclude', 'gems']
25
18
  end
26
- Jeweler::RubygemsDotOrgTasks.new
27
19
 
28
- require 'rake/testtask'
29
- Rake::TestTask.new(:test) do |test|
30
- test.libs << 'lib' << 'test'
31
- test.pattern = 'test/**/test_*.rb'
32
- test.verbose = true
20
+ desc "Generate code coverage"
21
+ RSpec::Core::RakeTask.new(:rcov) do |t|
22
+ t.pattern = "./spec/**/*_spec.rb" # don't need this, it's default.
23
+ t.rcov = true
24
+ t.rcov_opts = ['--exclude', 'spec', '--exclude', 'gems']
33
25
  end
34
26
 
35
- require 'rcov/rcovtask'
36
- Rcov::RcovTask.new do |test|
37
- test.libs << 'test'
38
- test.pattern = 'test/**/test_*.rb'
39
- test.verbose = true
40
- end
41
-
42
- task :default => :test
27
+ task :default => :rcov
28
+ task :hudson => [:rcov, :doc]
43
29
 
44
- require 'rake/rdoctask'
45
- Rake::RDocTask.new do |rdoc|
46
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
30
+ # Use yard to build docs
31
+ begin
32
+ require 'yard'
33
+ require 'yard/rake/yardoc_task'
34
+ project_root = File.expand_path(File.dirname(__FILE__))
35
+ doc_destination = File.join(project_root, 'doc')
47
36
 
48
- rdoc.rdoc_dir = 'rdoc'
49
- rdoc.title = "lockit #{version}"
50
- rdoc.rdoc_files.include('README*')
51
- rdoc.rdoc_files.include('lib/**/*.rb')
52
- end
37
+ YARD::Rake::YardocTask.new(:doc) do |yt|
38
+ yt.files = Dir.glob(File.join(project_root, 'lib', '**', '*.rb')) +
39
+ [ File.join(project_root, 'README.textile') ]
40
+ yt.options = ['--output-dir', doc_destination, '--readme', 'README.rdoc']
41
+ end
42
+ rescue LoadError
43
+ desc "Generate YARD Documentation"
44
+ task :doc do
45
+ abort "Please install the YARD gem to generate rdoc."
46
+ end
47
+ end
data/bin/lockit CHANGED
File without changes
data/bin/unlockit CHANGED
File without changes
@@ -0,0 +1,3 @@
1
+ module LockIt
2
+ VERSION = "0.1.1"
3
+ end
data/lib/lockit.rb CHANGED
@@ -3,12 +3,15 @@ module LockIt
3
3
  FILENAME='lock.txt'
4
4
 
5
5
  module Mixin
6
+
7
+ # Lock the directory
6
8
  def lock args = {}
7
9
  return false if locked?
8
10
  write_lock args
9
11
  self
10
12
  end
11
13
 
14
+ # @param DateTime :release When will this lock likely be released?
12
15
  def revise_lock args
13
16
  return false unless locked?
14
17
  # xxx is it my lock to revise?
@@ -16,6 +19,8 @@ module LockIt
16
19
  self
17
20
  end
18
21
 
22
+ # If the directory is locked already, return false
23
+ # Otherwise, lock the directory
19
24
  def try_lock args = {}
20
25
  return false if locked?
21
26
  lock args
@@ -47,6 +52,8 @@ module LockIt
47
52
  end
48
53
 
49
54
  private
55
+
56
+ # return the path to the closest lock file in this directory
50
57
  def closest_lock_file
51
58
  d = []
52
59
  last = nil
@@ -62,6 +69,7 @@ module LockIt
62
69
  def lock_file
63
70
  File.join(self.path, LockIt::FILENAME)
64
71
  end
72
+
65
73
  def write_lock args
66
74
  File.open(lock_file, 'w') do |f|
67
75
  f.write(lock_content(args))
data/lockit.gemspec CHANGED
@@ -1,68 +1,28 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
1
  # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "lockit/version"
5
4
 
6
5
  Gem::Specification.new do |s|
7
- s.name = %q{lockit}
8
- s.version = "0.0.0"
6
+ s.name = %q{lockit}
7
+ s.version = LockIt::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Chris Beer", "Bess Sadler"]
10
+ s.email = %q{chris@cbeer.info}
11
+ s.homepage = "https://github.com/microservices/lockit"
12
+ s.summary = %q{A ruby implementation of LockIt: A Simple File-based Convention for Resource Locking}
13
+ s.description = %q{A ruby implementation of LockIt: A Simple File-based Convention for Resource Locking}
9
14
 
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Chris Beer"]
12
- s.date = %q{2010-11-26}
13
- s.email = %q{chris@cbeer.info}
14
- s.executables = ["lockit", "unlockit"]
15
- s.extra_rdoc_files = [
16
- "LICENSE.txt",
17
- "README.rdoc",
18
- "TODO"
19
- ]
20
- s.files = [
21
- ".document",
22
- "Gemfile",
23
- "Gemfile.lock",
24
- "LICENSE.txt",
25
- "README.rdoc",
26
- "Rakefile",
27
- "TODO",
28
- "VERSION",
29
- "bin/lockit",
30
- "bin/unlockit",
31
- "lib/lockit.rb",
32
- "lockit.gemspec",
33
- "test/helper.rb",
34
- "test/test_lockit.rb"
35
- ]
36
- s.homepage = %q{http://github.com/cbeer/lockit}
37
- s.licenses = ["MIT"]
15
+ s.files = `git ls-files`.split("\n")
16
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
38
18
  s.require_paths = ["lib"]
39
- s.rubygems_version = %q{1.3.7}
40
- s.summary = %q{A ruby implementation of LockIt: A Simple File-based Convention for Resource Locking}
41
- s.test_files = [
42
- "test/helper.rb",
43
- "test/test_lockit.rb"
44
- ]
45
-
46
- if s.respond_to? :specification_version then
47
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
48
- s.specification_version = 3
49
-
50
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
51
- s.add_development_dependency(%q<shoulda>, [">= 0"])
52
- s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
53
- s.add_development_dependency(%q<jeweler>, ["~> 1.5.1"])
54
- s.add_development_dependency(%q<rcov>, [">= 0"])
55
- else
56
- s.add_dependency(%q<shoulda>, [">= 0"])
57
- s.add_dependency(%q<bundler>, ["~> 1.0.0"])
58
- s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
59
- s.add_dependency(%q<rcov>, [">= 0"])
60
- end
61
- else
62
- s.add_dependency(%q<shoulda>, [">= 0"])
63
- s.add_dependency(%q<bundler>, ["~> 1.0.0"])
64
- s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
65
- s.add_dependency(%q<rcov>, [">= 0"])
66
- end
19
+
20
+
21
+ # Bundler will install these gems too if you've checked this out from source from git and run 'bundle install'
22
+ # It will not add these as dependencies if you require lyber-core for other projects
23
+ s.add_development_dependency "rake"
24
+ s.add_development_dependency "bundler"
25
+ s.add_development_dependency "rspec"
26
+ s.add_development_dependency 'rcov'
27
+ s.add_development_dependency 'yard'
67
28
  end
68
-
@@ -0,0 +1,104 @@
1
+ require File.join(File.dirname(__FILE__), "..", "lib", "lockit.rb")
2
+ require 'tmpdir'
3
+ require 'rspec'
4
+
5
+ describe LockIt::Dir do
6
+
7
+ describe "locking and unlocking" do
8
+
9
+ it "is unlocked by default" do
10
+ Dir.mktmpdir do |d|
11
+ lockit_dir = LockIt::Dir.new(d)
12
+ lockit_dir.locked?.should eql(false)
13
+ end
14
+ end
15
+
16
+ it "can be locked and unlocked" do
17
+ Dir.mktmpdir do |d|
18
+ lockit_dir = LockIt::Dir.new(d)
19
+ lockit_dir.lock
20
+ lockit_dir.locked?.should eql(true)
21
+ lockit_dir.unlock
22
+ lockit_dir.locked?.should eql(false)
23
+ end
24
+ end
25
+
26
+ end
27
+
28
+ describe "#try_lock" do
29
+
30
+ it "tries the lock & returns false if it is already locked" do
31
+ Dir.mktmpdir do |d|
32
+ lockit_dir = LockIt::Dir.new(d)
33
+ lockit_dir.lock
34
+ lockit_dir.try_lock.should eql(false)
35
+ end
36
+ end
37
+
38
+ it "tries the lock & unlocks the dir if it isn't yet locked" do
39
+ Dir.mktmpdir do |d|
40
+ lockit_dir = LockIt::Dir.new(d)
41
+ lockit_dir.try_lock
42
+ lockit_dir.locked?.should eql(true)
43
+ end
44
+ end
45
+
46
+ end
47
+
48
+ describe "#lock_info" do
49
+
50
+ it "knows the location of the lockfile" do
51
+ Dir.mktmpdir do |d|
52
+ lockit_dir = LockIt::Dir.new(d)
53
+ lockit_dir.try_lock
54
+ info = lockit_dir.lock_info
55
+ info[:file].should eql("#{d}/#{LockIt::FILENAME}")
56
+ end
57
+ end
58
+
59
+ it "knows when it was created" do
60
+ Dir.mktmpdir do |d|
61
+ lockit_dir = LockIt::Dir.new(d)
62
+ lockit_dir.try_lock
63
+ info = lockit_dir.lock_info
64
+ obtained = DateTime.parse(info[:obtained])
65
+ obtained.should be_instance_of(DateTime)
66
+ end
67
+ end
68
+
69
+ end
70
+
71
+ describe "#revise_lock" do
72
+
73
+ it "returns false if called on an unlocked directory" do
74
+ Dir.mktmpdir do |d|
75
+ lockit_dir = LockIt::Dir.new(d)
76
+ lockit_dir.locked?.should eql(false)
77
+ release_time = Time.now + 60
78
+ lockit_dir.revise_lock(:release => release_time).should eql(false)
79
+ end
80
+ end
81
+
82
+ it "adds a release time to a locked directory" do
83
+ Dir.mktmpdir do |d|
84
+ lockit_dir = LockIt::Dir.new(d)
85
+ lockit_dir.lock
86
+ lockit_dir.locked?.should eql(true)
87
+ release_time = Time.now + 60
88
+ lockit_dir.revise_lock(:release => release_time)
89
+ @info = lockit_dir.lock_info
90
+ DateTime.parse(@info[:release]).should be_instance_of(DateTime)
91
+ end
92
+ end
93
+
94
+ it "reports its release time" do
95
+ @pending
96
+ end
97
+
98
+ it "reports if no release time has been set" do
99
+ @pending
100
+ end
101
+
102
+ end
103
+
104
+ end
metadata CHANGED
@@ -1,28 +1,28 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lockit
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
5
- prerelease: false
4
+ hash: 25
5
+ prerelease:
6
6
  segments:
7
7
  - 0
8
- - 0
9
- - 0
10
- version: 0.0.0
8
+ - 1
9
+ - 1
10
+ version: 0.1.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Chris Beer
14
+ - Bess Sadler
14
15
  autorequire:
15
16
  bindir: bin
16
17
  cert_chain: []
17
18
 
18
- date: 2010-11-26 00:00:00 -05:00
19
+ date: 2011-06-09 00:00:00 -05:00
19
20
  default_executable:
20
21
  dependencies:
21
22
  - !ruby/object:Gem::Dependency
22
- type: :development
23
+ name: rake
23
24
  prerelease: false
24
- name: shoulda
25
- version_requirements: &id001 !ruby/object:Gem::Requirement
25
+ requirement: &id001 !ruby/object:Gem::Requirement
26
26
  none: false
27
27
  requirements:
28
28
  - - ">="
@@ -31,44 +31,54 @@ dependencies:
31
31
  segments:
32
32
  - 0
33
33
  version: "0"
34
- requirement: *id001
35
- - !ruby/object:Gem::Dependency
36
34
  type: :development
37
- prerelease: false
35
+ version_requirements: *id001
36
+ - !ruby/object:Gem::Dependency
38
37
  name: bundler
39
- version_requirements: &id002 !ruby/object:Gem::Requirement
38
+ prerelease: false
39
+ requirement: &id002 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
- - - ~>
42
+ - - ">="
43
43
  - !ruby/object:Gem::Version
44
- hash: 23
44
+ hash: 3
45
45
  segments:
46
- - 1
47
46
  - 0
48
- - 0
49
- version: 1.0.0
50
- requirement: *id002
51
- - !ruby/object:Gem::Dependency
47
+ version: "0"
52
48
  type: :development
49
+ version_requirements: *id002
50
+ - !ruby/object:Gem::Dependency
51
+ name: rspec
53
52
  prerelease: false
54
- name: jeweler
55
- version_requirements: &id003 !ruby/object:Gem::Requirement
53
+ requirement: &id003 !ruby/object:Gem::Requirement
56
54
  none: false
57
55
  requirements:
58
- - - ~>
56
+ - - ">="
59
57
  - !ruby/object:Gem::Version
60
- hash: 1
58
+ hash: 3
61
59
  segments:
62
- - 1
63
- - 5
64
- - 1
65
- version: 1.5.1
66
- requirement: *id003
60
+ - 0
61
+ version: "0"
62
+ type: :development
63
+ version_requirements: *id003
67
64
  - !ruby/object:Gem::Dependency
65
+ name: rcov
66
+ prerelease: false
67
+ requirement: &id004 !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ hash: 3
73
+ segments:
74
+ - 0
75
+ version: "0"
68
76
  type: :development
77
+ version_requirements: *id004
78
+ - !ruby/object:Gem::Dependency
79
+ name: yard
69
80
  prerelease: false
70
- name: rcov
71
- version_requirements: &id004 !ruby/object:Gem::Requirement
81
+ requirement: &id005 !ruby/object:Gem::Requirement
72
82
  none: false
73
83
  requirements:
74
84
  - - ">="
@@ -77,37 +87,37 @@ dependencies:
77
87
  segments:
78
88
  - 0
79
89
  version: "0"
80
- requirement: *id004
81
- description:
90
+ type: :development
91
+ version_requirements: *id005
92
+ description: "A ruby implementation of LockIt: A Simple File-based Convention for Resource Locking"
82
93
  email: chris@cbeer.info
83
94
  executables:
84
95
  - lockit
85
96
  - unlockit
86
97
  extensions: []
87
98
 
88
- extra_rdoc_files:
89
- - LICENSE.txt
90
- - README.rdoc
91
- - TODO
99
+ extra_rdoc_files: []
100
+
92
101
  files:
93
102
  - .document
103
+ - .gitignore
104
+ - .rvmrc
94
105
  - Gemfile
95
106
  - Gemfile.lock
96
107
  - LICENSE.txt
97
108
  - README.rdoc
98
109
  - Rakefile
99
110
  - TODO
100
- - VERSION
101
111
  - bin/lockit
102
112
  - bin/unlockit
103
113
  - lib/lockit.rb
114
+ - lib/lockit/version.rb
104
115
  - lockit.gemspec
105
- - test/helper.rb
106
- - test/test_lockit.rb
116
+ - spec/lockit_spec.rb
107
117
  has_rdoc: true
108
- homepage: http://github.com/cbeer/lockit
109
- licenses:
110
- - MIT
118
+ homepage: https://github.com/microservices/lockit
119
+ licenses: []
120
+
111
121
  post_install_message:
112
122
  rdoc_options: []
113
123
 
@@ -134,10 +144,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
134
144
  requirements: []
135
145
 
136
146
  rubyforge_project:
137
- rubygems_version: 1.3.7
147
+ rubygems_version: 1.6.2
138
148
  signing_key:
139
149
  specification_version: 3
140
150
  summary: "A ruby implementation of LockIt: A Simple File-based Convention for Resource Locking"
141
151
  test_files:
142
- - test/helper.rb
143
- - test/test_lockit.rb
152
+ - spec/lockit_spec.rb
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.0.0
data/test/helper.rb DELETED
@@ -1,18 +0,0 @@
1
- require 'rubygems'
2
- require 'bundler'
3
- begin
4
- Bundler.setup(:default, :development)
5
- rescue Bundler::BundlerError => e
6
- $stderr.puts e.message
7
- $stderr.puts "Run `bundle install` to install missing gems"
8
- exit e.status_code
9
- end
10
- require 'test/unit'
11
- require 'shoulda'
12
-
13
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
- $LOAD_PATH.unshift(File.dirname(__FILE__))
15
- require 'lockit'
16
-
17
- class Test::Unit::TestCase
18
- end
data/test/test_lockit.rb DELETED
@@ -1,33 +0,0 @@
1
- require 'helper'
2
-
3
- class MockLockitDir
4
- include LockIt::Mixin
5
-
6
- def path
7
- '.'
8
- end
9
-
10
- def test_lock_content args = {}
11
- lock_content args
12
- end
13
- def test_lock_file
14
- lock_file
15
- end
16
-
17
-
18
- end
19
- class TestLockit < Test::Unit::TestCase
20
- def test_lock_name
21
- d = MockLockitDir.new
22
-
23
- assert_equal(d.test_lock_file, './lock.txt')
24
- end
25
- def test_lock_content
26
- d = MockLockitDir.new
27
-
28
- str = d.test_lock_content
29
-
30
- assert_match /[^ ]+ \d+/, str
31
-
32
- end
33
- end