Class: Appydave::Tools::BrainQuery

Inherits:
Object
  • Object
show all
Defined in:
lib/appydave/tools/brain_context/brain_finder.rb

Overview

Queries brains-index.json to find brain files

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ BrainQuery

Returns a new instance of BrainQuery.



9
10
11
12
13
# File 'lib/appydave/tools/brain_context/brain_finder.rb', line 9

def initialize(options)
  @options = options
  @index = nil
  @alias_map = nil
end

Instance Method Details

#findObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/appydave/tools/brain_context/brain_finder.rb', line 15

def find
  return [] unless @options.brain_query?

  load_index!
  paths = []

  # Active brains: return all high-activity brains
  paths.concat(find_active) if @options.active

  # Handle brain name/tag/alias queries (unified)
  @options.brain_names.each do |name|
    paths.concat(find_by_name(name))
  end

  # Handle category queries
  @options.categories.each do |category|
    paths.concat(find_by_category(category))
  end

  paths.uniq.sort
end

#find_metaObject



37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/appydave/tools/brain_context/brain_finder.rb', line 37

def find_meta
  return [] unless @options.brain_query?

  load_index!
  entries = []

  entries.concat(active_meta_entries) if @options.active
  @options.brain_names.each { |name| entries.concat(meta_entries_by_name(name)) }
  @options.categories.each { |cat| entries.concat(meta_entries_by_category(cat)) }

  entries.uniq { |e| e['name'] }.sort_by { |e| e['name'] }
end