Class: Kreator::Plugin
- Inherits:
-
Object
- Object
- Kreator::Plugin
- Defined in:
- lib/kreator/plugin.rb
Instance Attribute Summary collapse
-
#manifest ⇒ Object
readonly
Returns the value of attribute manifest.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #autoload_skill_names ⇒ Object
- #description ⇒ Object
- #enabled? ⇒ Boolean
- #expand_path_inside!(relative_path) ⇒ Object
-
#initialize(path:, manifest:) ⇒ Plugin
constructor
A new instance of Plugin.
- #instructions_path ⇒ Object
- #name ⇒ Object
- #prompts_dir ⇒ Object
- #skills_dir ⇒ Object
- #to_h ⇒ Object
- #tool_specs ⇒ Object
- #version ⇒ Object
Constructor Details
#initialize(path:, manifest:) ⇒ Plugin
Returns a new instance of Plugin.
7 8 9 10 |
# File 'lib/kreator/plugin.rb', line 7 def initialize(path:, manifest:) @path = File.(path) @manifest = manifest end |
Instance Attribute Details
#manifest ⇒ Object (readonly)
Returns the value of attribute manifest.
5 6 7 |
# File 'lib/kreator/plugin.rb', line 5 def manifest @manifest end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
5 6 7 |
# File 'lib/kreator/plugin.rb', line 5 def path @path end |
Instance Method Details
#autoload_skill_names ⇒ Object
40 41 42 |
# File 'lib/kreator/plugin.rb', line 40 def autoload_skill_names Array(manifest["autoload_skills"]).map(&:to_s) end |
#description ⇒ Object
20 21 22 |
# File 'lib/kreator/plugin.rb', line 20 def description manifest["description"].to_s end |
#enabled? ⇒ Boolean
24 25 26 |
# File 'lib/kreator/plugin.rb', line 24 def enabled? manifest.fetch("enabled", true) end |
#expand_path_inside!(relative_path) ⇒ Object
48 49 50 51 52 53 54 55 |
# File 'lib/kreator/plugin.rb', line 48 def (relative_path) = File.(relative_path, path) root = "#{path}#{File::SEPARATOR}" raise ArgumentError, "plugin path escapes plugin directory: #{relative_path}" unless == path || .start_with?(root) raise ArgumentError, "plugin file not found: #{}" unless File.file?() end |
#instructions_path ⇒ Object
28 29 30 |
# File 'lib/kreator/plugin.rb', line 28 def instructions_path File.join(path, "instructions.md") end |
#name ⇒ Object
12 13 14 |
# File 'lib/kreator/plugin.rb', line 12 def name manifest.fetch("name") end |
#prompts_dir ⇒ Object
32 33 34 |
# File 'lib/kreator/plugin.rb', line 32 def prompts_dir File.join(path, "prompts") end |
#skills_dir ⇒ Object
36 37 38 |
# File 'lib/kreator/plugin.rb', line 36 def skills_dir File.join(path, "skills") end |
#to_h ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/kreator/plugin.rb', line 57 def to_h { "name" => name, "version" => version, "description" => description, "path" => path, "enabled" => enabled?, "autoload_skills" => autoload_skill_names, "tools" => tool_specs }.compact end |
#tool_specs ⇒ Object
44 45 46 |
# File 'lib/kreator/plugin.rb', line 44 def tool_specs Array(manifest["tools"]) end |
#version ⇒ Object
16 17 18 |
# File 'lib/kreator/plugin.rb', line 16 def version manifest["version"] end |