Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: call block with plugin_default_context #311

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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