Class: Cline::Skill
- Inherits:
-
Object
- Object
- Cline::Skill
- Includes:
- Cline::Serializable::Dir
- Defined in:
- lib/cline/skill.rb
Overview
A skill defined in a directory
Instance Attribute Summary
Attributes included from Cline::Serializable::Dir
Internal collapse
-
#initialize ⇒ Skill
constructor
Constructor.
Methods included from Cline::Serializable::Dir
included, #initialize_from_dir, #subpath
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
Equality check.
-
#disable ⇒ Object
Disable the skill.
-
#enable ⇒ Object
Enable the skill.
-
#enabled? ⇒ Boolean
Is the skill enabled?.
-
#files ⇒ Hash{String => FileContent, nil}
Get the files of this skill.
-
#name ⇒ String
Get the skill's name.
-
#save ⇒ Object
Save the skill files.
-
#yaml_front_matter ⇒ Hash{Symbol => Object}?
Get the skill's YAML front matter.
Constructor Details
#initialize ⇒ Skill
Constructor
89 90 91 92 |
# File 'lib/cline/skill.rb', line 89 def initialize @files = {} @files_discovered = false end |
Instance Method Details
#==(other) ⇒ Boolean
Equality check
31 32 33 34 35 |
# File 'lib/cline/skill.rb', line 31 def ==(other) other.is_a?(Skill) && other.name == name && other.files.compact == files.compact end |
#disable ⇒ Object
Disable the skill
78 79 80 81 82 83 84 |
# File 'lib/cline/skill.rb', line 78 def disable return unless enabled? modify_skill_front_matter do |front_matter| front_matter.merge('disabled' => true) end end |
#enable ⇒ Object
Enable the skill
69 70 71 72 73 74 75 |
# File 'lib/cline/skill.rb', line 69 def enable return if enabled? modify_skill_front_matter do |front_matter| front_matter.except('disabled') end end |
#enabled? ⇒ Boolean
Returns Is the skill enabled?.
64 65 66 |
# File 'lib/cline/skill.rb', line 64 def enabled? !yaml_front_matter || yaml_front_matter[:disabled] != true end |
#files ⇒ Hash{String => FileContent, nil}
Get the files of this skill
40 41 42 43 |
# File 'lib/cline/skill.rb', line 40 def files discover_files @files end |
#name ⇒ String
Get the skill's name
15 16 17 |
# File 'lib/cline/skill.rb', line 15 def name File.basename(dir) end |
#save ⇒ Object
Save the skill files
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/cline/skill.rb', line 46 def save raise 'This instance has not been initialized from a Skill directory' unless dir # First create/update all known files files.each do |file_path, file_content| next unless file_content file_full_path = File.join(dir, file_path) FileUtils.mkdir_p(File.dirname(file_full_path)) File.write(file_full_path, file_content.content) end # Then delete any file that is not known each_file do |file_path| File.unlink(File.join(dir, file_path)) unless files[file_path] end end |
#yaml_front_matter ⇒ Hash{Symbol => Object}?
Get the skill's YAML front matter
22 23 24 25 |
# File 'lib/cline/skill.rb', line 22 def yaml_front_matter content = skill_file_content('SKILL.md')&.content JSON.parse(JSON[FrontMatterParser::Parser.new(:md).call(content).front_matter], symbolize_names: true) if content end |