Class: Kreator::Plugin

Inherits:
Object
  • Object
show all
Defined in:
lib/kreator/plugin.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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.expand_path(path)
  @manifest = manifest
end

Instance Attribute Details

#manifestObject (readonly)

Returns the value of attribute manifest.



5
6
7
# File 'lib/kreator/plugin.rb', line 5

def manifest
  @manifest
end

#pathObject (readonly)

Returns the value of attribute path.



5
6
7
# File 'lib/kreator/plugin.rb', line 5

def path
  @path
end

Instance Method Details

#descriptionObject



20
21
22
# File 'lib/kreator/plugin.rb', line 20

def description
  manifest["description"].to_s
end

#enabled?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/kreator/plugin.rb', line 24

def enabled?
  manifest.fetch("enabled", true)
end

#expand_path_inside!(relative_path) ⇒ Object

Raises:

  • (ArgumentError)


44
45
46
47
48
49
50
51
# File 'lib/kreator/plugin.rb', line 44

def expand_path_inside!(relative_path)
  expanded = File.expand_path(relative_path, path)
  root = "#{path}#{File::SEPARATOR}"
  raise ArgumentError, "plugin path escapes plugin directory: #{relative_path}" unless expanded == path || expanded.start_with?(root)
  raise ArgumentError, "plugin file not found: #{expanded}" unless File.file?(expanded)

  expanded
end

#instructions_pathObject



28
29
30
# File 'lib/kreator/plugin.rb', line 28

def instructions_path
  File.join(path, "instructions.md")
end

#nameObject



12
13
14
# File 'lib/kreator/plugin.rb', line 12

def name
  manifest.fetch("name")
end

#prompts_dirObject



32
33
34
# File 'lib/kreator/plugin.rb', line 32

def prompts_dir
  File.join(path, "prompts")
end

#skills_dirObject



36
37
38
# File 'lib/kreator/plugin.rb', line 36

def skills_dir
  File.join(path, "skills")
end

#to_hObject



53
54
55
56
57
58
59
60
61
62
# File 'lib/kreator/plugin.rb', line 53

def to_h
  {
    "name" => name,
    "version" => version,
    "description" => description,
    "path" => path,
    "enabled" => enabled?,
    "tools" => tool_specs
  }.compact
end

#tool_specsObject



40
41
42
# File 'lib/kreator/plugin.rb', line 40

def tool_specs
  Array(manifest["tools"])
end

#versionObject



16
17
18
# File 'lib/kreator/plugin.rb', line 16

def version
  manifest["version"]
end