with_locking 0.0.1 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -16,13 +16,13 @@ Or install it yourself as:
16
16
 
17
17
  A block of code can be executed like so:
18
18
 
19
- WithLocking.do { puts "While I'm running other code run through WithLocking cannot run!" }
19
+ WithLocking.run { puts "While I'm running other code run through WithLocking cannot run!" }
20
20
 
21
21
  Alternatively, run the block of code with an optional name (recommended), that way multiple WithLocking blocks with different names can be invoked without conflicting:
22
22
 
23
- WithLocking.do(:name => "sleeper") { sleep 60 }
24
- WithLocking.do(:name => "sleeper") { puts "I won't execute and will return false because 'sleeper' is still running the first block." }
25
- WithLocking.do(:name => "other_name") { puts "But I will run because 'other_name' isn't running!" }
23
+ WithLocking.run(:name => "sleeper") { sleep 60 }
24
+ WithLocking.run(:name => "sleeper") { puts "I won't execute and will return false because 'sleeper' is still running the first block." }
25
+ WithLocking.run(:name => "other_name") { puts "But I will run because 'other_name' isn't running!" }
26
26
  # => "But I will run because 'other_name' isn't running!"
27
27
 
28
28
  To simply test if a named block is still running without executing a block use the `locked?` method:
@@ -32,7 +32,7 @@ To simply test if a named block is still running without executing a block use t
32
32
 
33
33
  To raise an exception when the block isn't run (rather than simply returning false), use the `do!` method:
34
34
 
35
- WithLocking.do!(:name => "sleeper") { puts "Blah" }
35
+ WithLocking.run!(:name => "sleeper") { puts "Blah" }
36
36
  # => raises an error if 'sleeper' block is still running from before
37
37
 
38
38
  ## Contributing
data/lib/with_locking.rb CHANGED
@@ -2,7 +2,7 @@ require "with_locking/version"
2
2
 
3
3
  module WithLocking
4
4
 
5
- def self.do(options = {}, &block)
5
+ def self.run(options = {}, &block)
6
6
  raise "No block given" unless block_given?
7
7
 
8
8
  name = options[:name] || "locking_service_task"
@@ -27,8 +27,8 @@ module WithLocking
27
27
  return true
28
28
  end
29
29
 
30
- def self.do!(options = {}, &block)
31
- raise "locked process still running" unless self.do(options, &block)
30
+ def self.run!(options = {}, &block)
31
+ raise "locked process still running" unless self.run(options, &block)
32
32
  end
33
33
 
34
34
  def self.locked?(name)
@@ -1,3 +1,3 @@
1
1
  module WithLocking
2
- VERSION = "0.0.1"
2
+ VERSION = "1.0.1"
3
3
  end
@@ -9,36 +9,36 @@ describe WithLocking do
9
9
  File.stub(:delete)
10
10
  end
11
11
 
12
- describe "#do" do
12
+ describe "#run" do
13
13
 
14
14
  it "writes a pid file" do
15
15
  File.should_receive(:open).with(path, "w")
16
- WithLocking.do(:name => file_name) { }
16
+ WithLocking.run(:name => file_name) { }
17
17
  end
18
18
 
19
19
  it "executes the given block" do
20
20
  my_test_array = []
21
- WithLocking.do { my_test_array << 1 }
21
+ WithLocking.run { my_test_array << 1 }
22
22
  my_test_array.count.should == 1
23
23
  end
24
24
 
25
25
  it "deletes the pid file" do
26
26
  File.should_receive(:delete).with(path)
27
- WithLocking.do(:name => file_name) {}
27
+ WithLocking.run(:name => file_name) {}
28
28
  end
29
29
 
30
30
  it "should not execute the block if the pid file already exists" do
31
31
  File.stub(:exists?).and_return(true)
32
- WithLocking.do {}.should == false
32
+ WithLocking.run {}.should == false
33
33
  end
34
34
 
35
35
  end
36
36
 
37
- describe "#do!" do
37
+ describe "#run!" do
38
38
 
39
39
  it "raises an exception if the pid file already exists" do
40
40
  File.stub(:exists?).and_return(true)
41
- lambda { WithLocking.do! {} }.should raise_error(RuntimeError, 'locked process still running')
41
+ lambda { WithLocking.run! {} }.should raise_error(RuntimeError, 'locked process still running')
42
42
  end
43
43
 
44
44
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: with_locking
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 1.0.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: