Class: Appydave::Tools::AppContext::AppQuery

Inherits:
Object
  • Object
show all
Defined in:
lib/appydave/tools/app_context/app_finder.rb

Overview

Queries locations.json to find app files via context.globs.json patterns.

Follows the same find/find_meta pattern as BrainQuery and OmiQuery.

Instance Method Summary collapse

Constructor Details

#initialize(options, jump_config: nil) ⇒ AppQuery

Returns a new instance of AppQuery.



12
13
14
15
# File 'lib/appydave/tools/app_context/app_finder.rb', line 12

def initialize(options, jump_config: nil)
  @options = options
  @jump_config = jump_config
end

Instance Method Details

#findObject

Return absolute file paths matching the query



18
19
20
21
22
23
24
25
# File 'lib/appydave/tools/app_context/app_finder.rb', line 18

def find
  return [] unless @options.query?

  apps = resolve_apps
  return [] if apps.empty?

  apps.flat_map { |app| expand_app(app) }.uniq.sort
end

#find_metaObject

Return structured metadata about the query results



28
29
30
31
32
33
34
35
# File 'lib/appydave/tools/app_context/app_finder.rb', line 28

def find_meta
  return [] unless @options.query?

  apps = resolve_apps
  return [] if apps.empty?

  apps.map { |app| build_meta(app) }
end

#list_appsObject

List all apps that have context.globs.json



49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/appydave/tools/app_context/app_finder.rb', line 49

def list_apps
  jump_config.locations
             .select { |loc| File.exist?(File.join(expand_path(loc.path), 'context.globs.json')) }
             .map do |loc|
               loader = build_loader(loc)
               {
                 'key' => loc.key,
                 'path' => expand_path(loc.path),
                 'pattern' => loader.pattern,
                 'glob_count' => loader.globs.size
               }
             end
end

#list_globs(app_name) ⇒ Object

List all available glob names for a specific app



38
39
40
41
42
43
44
45
46
# File 'lib/appydave/tools/app_context/app_finder.rb', line 38

def list_globs(app_name)
  location = find_location(app_name)
  return [] unless location

  loader = build_loader(location)
  return [] unless loader.available?

  loader.available_names
end