Skip to content

Commit c8d1b25

Browse files
committed
Accept thread_safe as a keyword argument
Preserve the positional argument while allowing callers to use the clearer keyword form.
1 parent d637dad commit c8d1b25

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

lib/pstore.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -367,12 +367,13 @@ class Error < StandardError
367367
#
368368
# A \PStore object is
369369
# {reentrant}[https://en.wikipedia.org/wiki/Reentrancy_(computing)].
370-
# If argument +thread_safe+ is given as +true+,
370+
# If argument or keyword argument +thread_safe+ is given as +true+,
371371
# the object is also thread-safe (at the cost of a small performance penalty):
372372
#
373373
# store = PStore.new(path, true)
374+
# store = PStore.new(path, thread_safe: true)
374375
#
375-
def initialize(file, thread_safe = false)
376+
def initialize(file, _thread_safe = false, thread_safe: _thread_safe)
376377
dir = File::dirname(file)
377378
unless File::directory? dir
378379
raise PStore::Error, format("directory %s does not exist", dir)

test/test_pstore.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,13 @@ def test_thread_safe
128128
File.unlink(second_file) rescue nil
129129
end
130130

131+
def test_thread_safe_argument
132+
assert_equal false, PStore.new(@pstore_file).instance_variable_get(:@thread_safe)
133+
assert_equal true, PStore.new(@pstore_file, true).instance_variable_get(:@thread_safe)
134+
assert_equal true, PStore.new(@pstore_file, thread_safe: true).instance_variable_get(:@thread_safe)
135+
assert_equal false, PStore.new(@pstore_file, true, thread_safe: false).instance_variable_get(:@thread_safe)
136+
end
137+
131138
def test_nested_transaction_raises_error
132139
assert_raise(PStore::Error) do
133140
@pstore.transaction { @pstore.transaction { } }

0 commit comments

Comments
 (0)