Skip to content

Commit a8b1655

Browse files
committed
Switch ExtensionSpecifier from #sqlite_extension_path to #to_path
which is a way better idea, thanks @tenderlove
1 parent 175c05e commit a8b1655

File tree

2 files changed

+25
-12
lines changed

2 files changed

+25
-12
lines changed

lib/sqlite3/database.rb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,12 @@ module SQLite3
5050
# db.enable_load_extension(true)
5151
# db.load_extension("/path/to/extension")
5252
#
53-
# As of v2.4.0, it's also possible to pass an object that responds to
54-
# +#sqlite_extension_path+. This documentation will refer to the supported interface as
55-
# +_ExtensionSpecifier+, which can be expressed in RBS syntax as:
53+
# As of v2.4.0, it's also possible to pass an object that responds to +#to_path+. This
54+
# documentation will refer to the supported interface as +_ExtensionSpecifier+, which can be
55+
# expressed in RBS syntax as:
5656
#
5757
# interface _ExtensionSpecifier
58-
# def sqlite_extension_path: () → String
58+
# def to_path: () → String
5959
# end
6060
#
6161
# So, for example, if you are using the {sqlean gem}[https://github.com/flavorjones/sqlean-ruby]
@@ -718,7 +718,7 @@ def busy_handler_timeout=(milliseconds)
718718
#
719719
# [Parameters]
720720
# - +extension_specifier+: (String | +_ExtensionSpecifier+) If a String, it is the filesystem path
721-
# to the sqlite extension file. If an object that responds to #sqlite_extension_path, the
721+
# to the sqlite extension file. If an object that responds to #to_path, the
722722
# return value of that method is used as the filesystem path to the sqlite extension file.
723723
#
724724
# [Example] Using a filesystem path:
@@ -730,8 +730,8 @@ def busy_handler_timeout=(milliseconds)
730730
# db.load_extension(SQLean::VSV)
731731
#
732732
def load_extension(extension_specifier)
733-
if extension_specifier.respond_to?(:sqlite_extension_path)
734-
extension_specifier = extension_specifier.sqlite_extension_path
733+
if extension_specifier.respond_to?(:to_path)
734+
extension_specifier = extension_specifier.to_path
735735
elsif !extension_specifier.is_a?(String)
736736
raise TypeError, "extension_specifier #{extension_specifier.inspect} is not a String or a valid extension specifier object"
737737
end
@@ -747,11 +747,11 @@ def marshal_extensions(extensions) # :nodoc:
747747

748748
extensions.each do |extension|
749749
# marshall the extension into an object if it's the name of a constant that responds to
750-
# `#sqlite_extension_path`
750+
# `#to_path`
751751
if extension.is_a?(String)
752752
begin
753753
extension_spec = Object.const_get(extension)
754-
if extension_spec.respond_to?(:sqlite_extension_path)
754+
if extension_spec.respond_to?(:to_path)
755755
extension = extension_spec
756756
end
757757
rescue NameError

test/test_database.rb

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
module SQLite3
66
class FakeExtensionSpecifier
7-
def self.sqlite_extension_path
7+
def self.to_path
88
"/path/to/extension"
99
end
1010
end
@@ -672,20 +672,28 @@ def test_load_extension_error_with_nonexistent_path
672672
db.enable_load_extension(true)
673673

674674
assert_raises(SQLite3::Exception) { db.load_extension("/path/to/extension") }
675+
assert_raises(SQLite3::Exception) { db.load_extension(Pathname.new("foo")) }
675676
end
676677

677678
def test_load_extension_error_with_invalid_argument
678679
skip("extensions are not enabled") unless db.respond_to?(:load_extension)
680+
db.enable_load_extension(true)
679681

680682
assert_raises(TypeError) { db.load_extension(1) }
681-
assert_raises(TypeError) { db.load_extension(Pathname.new("foo")) }
683+
assert_raises(TypeError) { db.load_extension({a: 1}) }
684+
assert_raises(TypeError) { db.load_extension([]) }
685+
assert_raises(TypeError) { db.load_extension(Object.new) }
682686
end
683687

684688
def test_load_extension_with_an_extension_descriptor
685689
mock_database_load_extension_internal(db)
686690

687-
db.load_extension(FakeExtensionSpecifier)
691+
db.load_extension(Pathname.new("/path/to/ext2"))
692+
assert_equal(["/path/to/ext2"], db.load_extension_internal_path)
688693

694+
db.load_extension_internal_path.clear # reset
695+
696+
db.load_extension(FakeExtensionSpecifier)
689697
assert_equal(["/path/to/extension"], db.load_extension_internal_path)
690698
end
691699

@@ -712,6 +720,11 @@ def enable_load_extension(...)
712720
def test_marshal_extensions_object_is_an_extension_specifier
713721
mock_database_load_extension_internal(db)
714722

723+
db.marshal_extensions([Pathname.new("/path/to/extension")])
724+
assert_equal(["/path/to/extension"], db.load_extension_internal_path)
725+
726+
db.load_extension_internal_path.clear # reset
727+
715728
db.marshal_extensions([FakeExtensionSpecifier])
716729
assert_equal(["/path/to/extension"], db.load_extension_internal_path)
717730

0 commit comments

Comments
 (0)