Class: RailsOmnibar::Command::Search
- Defined in:
- lib/rails_omnibar/command/search.rb
Overview
Generic search.
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from Base
#description, #example, #if, #pattern, #resolver
Instance Method Summary collapse
-
#initialize(finder:, itemizer:, **kwargs) ⇒ Search
constructor
A new instance of Search.
Methods inherited from Base
Constructor Details
#initialize(finder:, itemizer:, **kwargs) ⇒ Search
Returns a new instance of Search.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/rails_omnibar/command/search.rb', line 13 def initialize(finder:, itemizer:, **kwargs) finder = RailsOmnibar.cast_to_proc(finder) itemizer = RailsOmnibar.cast_to_proc(itemizer) resolver = ->(value, controller:, omnibar:) do findings = finder.call(value, controller: controller, omnibar: ) findings = Array(findings) unless findings.respond_to?(:first) findings.first(.max_results).flat_map do |finding| itemizer.call(finding, controller: controller, omnibar: ) end end super(resolver: resolver, **kwargs) end |