Skip to content

Commit

Permalink
Merge pull request #311 from iberianpig/fix/skipped_calling_block_wit…
Browse files Browse the repository at this point in the history
…h_plugin_defaults_context

fix: call block with plugin_default_context
  • Loading branch information
iberianpig authored Sep 25, 2023
2 parents 617caf1 + d8a19d6 commit 04a943d
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/fusuma/config/searcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,10 @@ def plugin_default_context(request_context, &block)

return config[:context] if with_context(config[:context], &block)
end
complete_match_context
if complete_match_context
with_context(complete_match_context, &block)
complete_match_context
end
end
end
end
Expand Down
36 changes: 36 additions & 0 deletions spec/fusuma/config/searcher_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,42 @@ module Fusuma
end
end

describe ".find_context" do
around do |example|
ConfigHelper.load_config_yml = <<~CONFIG
---
context: { plugin_defaults: "libinput_command_input" }
plugin:
inputs:
libinput_command_input:
---
context: { plugin_defaults: "sendkey_executor" }
plugin:
executors:
sendkey_executor:
device_name: keyboard|Keyboard|KEYBOARD
CONFIG

example.run

ConfigHelper.clear_config_yml
end

it "should find matched context and matched value" do
request_context = {plugin_defaults: "sendkey_executor"}
fallbacks = [:no_context, :plugin_default_context]

device_name = nil
matched = Config::Searcher.find_context(request_context, fallbacks) do
# search device_name from sendkey_executor context
device_name = Config.search(Config::Index.new(%w[plugin executors sendkey_executor device_name]))
end

expect(matched).to eq request_context
expect(device_name).to eq "keyboard|Keyboard|KEYBOARD"
end
end

describe "private_method: :cache" do
it "should cache command" do
key = %w[event_type finger direction command].join(",")
Expand Down

0 comments on commit 04a943d

Please sign in to comment.