Class: Shadwire::Commands::Search

Inherits:
Object
  • Object
show all
Defined in:
lib/shadwire/commands/search.rb

Overview

Filters the registry catalog by a case-insensitive substring match on an item's name, title, description, or whenToUse. Read-only. With json: true it emits the matching catalog entries; otherwise a "name — title" line each.

whenToUse is searched because it is where the disambiguating vocabulary lives ("form", "modal", "overlay"); without it a search for "form" misses most of the form controls.

Constant Summary collapse

SEARCHABLE =
%w[name title description whenToUse].freeze

Instance Method Summary collapse

Constructor Details

#initialize(root:, query:, registry: nil, json: false, ui: UI.new) ⇒ Search

Returns a new instance of Search.



17
18
19
20
21
22
23
# File 'lib/shadwire/commands/search.rb', line 17

def initialize(root:, query:, registry: nil, json: false, ui: UI.new)
  @root = root.to_s
  @query = query.to_s
  @registry_override = registry
  @json = json
  @ui = ui
end

Instance Method Details

#callObject



25
26
27
28
29
30
# File 'lib/shadwire/commands/search.rb', line 25

def call
  client = RegistryClient.new(@registry_override || Config.load(@root).registry)
  matches = filter(client.index.fetch("items", []))
  emit(matches)
  matches
end