Class: Ask::Skills::Source::Filesystem

Inherits:
Base
  • Object
show all
Defined in:
lib/ask/skills/sources/filesystem.rb

Instance Method Summary collapse

Methods inherited from Base

#name

Constructor Details

#initialize(dir: nil, project_dir: nil, user_dir: nil) ⇒ Filesystem

Returns a new instance of Filesystem.



5
6
7
# File 'lib/ask/skills/sources/filesystem.rb', line 5

def initialize(dir: nil, project_dir: nil, user_dir: nil)
  @path = dir || project_dir || (user_dir ? File.expand_path(user_dir) : nil)
end

Instance Method Details

#loadObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/ask/skills/sources/filesystem.rb', line 9

def load
  return [] unless @path && Dir.exist?(@path)
  skills = []
  Dir.entries(@path).each do |entry|
    next if entry.start_with?(".")
    skill_dir = File.join(@path, entry)
    next unless File.directory?(skill_dir)
    skill_file = File.join(skill_dir, "SKILL.md")
    next unless File.exist?(skill_file)
    next if File.directory?(skill_file)
    if (skill = parse_skill(skill_file))
      skills << skill
    end
  end
  skills
end