Skip to content

Commit

Permalink
Fix config initializer (#23)
Browse files Browse the repository at this point in the history
Closes #22
  • Loading branch information
bhelx authored Jul 19, 2024
1 parent 21c196f commit 3c51091
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
extism (1.0.0)
extism (1.0.1)
ffi (~> 1.0)

GEM
Expand Down
2 changes: 1 addition & 1 deletion lib/extism/plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def initialize(wasm, environment: nil, functions: [], wasi: false, config: nil)
end
$PLUGINS[object_id] = { plugin: @plugin }
ObjectSpace.define_finalizer(self, $FREE_PLUGIN)
return unless !config.nil? and @plugin.null?
return if config.nil? or @plugin.null?

s = JSON.generate(config)
ptr = FFI::MemoryPointer.from_string(s)
Expand Down
2 changes: 1 addition & 1 deletion lib/extism/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Extism
VERSION = '1.0.0'
VERSION = '1.0.1'
end
5 changes: 4 additions & 1 deletion test/test_extism.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def test_that_it_has_a_version_number
end

def test_plugin_call
plugin = Extism::Plugin.new(vowels_manifest)
plugin = Extism::Plugin.new(vowels_manifest, config: { vowels: 'aeiouyAEIOUY' })
res = JSON.parse(plugin.call('count_vowels', 'this is a test'))
assert_equal res['count'], 4
res = JSON.parse(plugin.call('count_vowels', 'this is a test again'))
Expand All @@ -73,6 +73,9 @@ def test_plugin_call
assert_equal res['count'], 6
res = JSON.parse(plugin.call('count_vowels', '🌎hello🌎world🌎'))
assert_equal res['count'], 3
res = JSON.parse(plugin.call('count_vowels', 'does y count?'))
assert_equal res['count'], 5
assert_equal res['vowels'], 'aeiouyAEIOUY'
end

def test_can_free_plugin
Expand Down

0 comments on commit 3c51091

Please sign in to comment.