Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 011ecb8

Browse files
authored
Fix typo and incorrect methods (#37)
* Fix typo and incorrect methods * Bump version 1.0.5
1 parent 0ba8251 commit 011ecb8

3 files changed

Lines changed: 22 additions & 3 deletions

File tree

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
# frozen_string_literal: true
22

33
require 'singleton'
4+
require 'forwardable'
45

56
class ThreadLock
67
include Singleton
78

89
class << self
9-
delegate :thread=, :lock?, to: :instance
10+
extend Forwardable
11+
def_delegators :instance, :thread=, :thread, :lock?
1012
end
1113

1214
attr_accessor :thread
1315

1416
def lock?
1517
return false unless thread
1618

17-
thread.active?
19+
thread.alive?
1820
end
1921
end

lib/casbin-ruby/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# frozen_string_literal: true
22

33
module Casbin
4-
VERSION = '1.0.4'
4+
VERSION = '1.0.5'
55
end
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# frozen_string_literal: true
2+
3+
require 'casbin-ruby/util/thread_lock'
4+
5+
describe ThreadLock do
6+
it '#lock? with no thread' do
7+
expect(described_class).not_to be_lock
8+
end
9+
10+
it '#lock? with thread' do
11+
described_class.thread = Thread.new { loop }
12+
expect(described_class).to be_lock
13+
described_class.thread.exit
14+
sleep 0.001 # waiting exit
15+
expect(described_class).not_to be_lock
16+
end
17+
end

0 commit comments

Comments
 (0)