Class: RubynCode::Skills::Loader

Inherits:
Object
  • Object
show all
Defined in:
lib/rubyn_code/skills/loader.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(catalog) ⇒ Loader

Returns a new instance of Loader.



8
9
10
11
# File 'lib/rubyn_code/skills/loader.rb', line 8

def initialize(catalog)
  @catalog = catalog
  @loaded = {}
end

Instance Attribute Details

#catalogObject (readonly)

Returns the value of attribute catalog.



6
7
8
# File 'lib/rubyn_code/skills/loader.rb', line 6

def catalog
  @catalog
end

Instance Method Details

#descriptions_for_promptObject



32
33
34
# File 'lib/rubyn_code/skills/loader.rb', line 32

def descriptions_for_prompt
  catalog.descriptions
end

#load(name) ⇒ Object

Raises:



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/rubyn_code/skills/loader.rb', line 13

def load(name)
  name = name.to_s

  return @loaded[name] if @loaded.key?(name)

  path = catalog.find(name)
  raise Error, "Skill not found: #{name}" unless path

  doc = Document.parse_file(path)
  content = format_skill(doc)

  @loaded[name] = content
  content
end

#loadedObject



28
29
30
# File 'lib/rubyn_code/skills/loader.rb', line 28

def loaded
  @loaded.keys
end

#suggest_skills(codebase_index: nil, project_profile: nil) ⇒ Array<String>

Suggest skills based on what the codebase index reveals about the project.

Inspects class names, parent classes, and file paths in the index to detect common Rails patterns (Devise, ActionMailer, ActiveJob, etc.) and returns matching skill names.

Parameters:

  • codebase_index (RubynCode::Index::CodebaseIndex, nil) (defaults to: nil)
  • project_profile (Object, nil) (defaults to: nil)

    reserved for future profile-based hints

Returns:

  • (Array<String>)

    suggested skill names (not loaded automatically)



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/rubyn_code/skills/loader.rb', line 45

def suggest_skills(codebase_index: nil, project_profile: nil) # rubocop:disable Lint/UnusedMethodArgument, Metrics/CyclomaticComplexity -- project_profile reserved for future use
  return [] unless codebase_index

  suggestions = []
  node_names = codebase_index.nodes.map { |n| n['name'].to_s }
  node_files = codebase_index.nodes.map { |n| n['file'].to_s }

  suggestions << 'authentication' if detect_devise?(node_names, node_files)
  suggestions << 'mailer'         if detect_action_mailer?(node_names, node_files)
  suggestions << 'background-job' if detect_active_job?(node_names, node_files)

  suggestions
rescue StandardError
  []
end