Class: SkillBench::Commands::SkillNew
- Inherits:
-
Object
- Object
- SkillBench::Commands::SkillNew
- Defined in:
- lib/skill_bench/commands/skill_new.rb
Overview
Handles the skill-bench skill new command
Constant Summary collapse
- RAILS_TEMPLATES =
{ 'service_object' => 'service.rb', 'concern' => 'concern.rb', 'active_record_model' => 'model.rb' }.freeze
Class Method Summary collapse
-
.advanced_skill_template(name) ⇒ String
Generate advanced skill template.
-
.camelize(string) ⇒ String
Convert snake_case to CamelCase.
-
.create_advanced_skill(path, name) ⇒ void
Create an advanced skill with Ruby class.
-
.create_rails_skill(path, name, template) ⇒ void
Create a Rails skill using templates.
-
.create_simple_skill(path, name) ⇒ void
Create a simple skill with SKILL.md.
-
.run(name:, mode: 'simple', template: 'service_object') ⇒ void
Run the skill new command.
-
.simple_skill_template(name) ⇒ String
Generate simple skill template.
Class Method Details
.advanced_skill_template(name) ⇒ String
Generate advanced skill template
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/skill_bench/commands/skill_new.rb', line 75 def self.advanced_skill_template(name) class_name = camelize(name) <<~RUBY # frozen_string_literal: true module SkillBench module Skills class #{class_name} def initialize; end def call # Implement skill logic here end end end end RUBY end |
.camelize(string) ⇒ String
Convert snake_case to CamelCase
68 69 70 |
# File 'lib/skill_bench/commands/skill_new.rb', line 68 def self.camelize(string) string.split(/[_\s]+/).map(&:capitalize).join end |
.create_advanced_skill(path, name) ⇒ void
This method returns an undefined value.
Create an advanced skill with Ruby class
43 44 45 |
# File 'lib/skill_bench/commands/skill_new.rb', line 43 def self.create_advanced_skill(path, name) File.write(File.join(path, 'skill.rb'), advanced_skill_template(name)) end |
.create_rails_skill(path, name, template) ⇒ void
This method returns an undefined value.
Create a Rails skill using templates
105 106 107 108 109 110 111 112 113 114 |
# File 'lib/skill_bench/commands/skill_new.rb', line 105 def self.create_rails_skill(path, name, template) file_name = RAILS_TEMPLATES[template] raise ArgumentError, "Invalid template: #{template}. Use one of: #{RAILS_TEMPLATES.keys.join(', ')}." unless file_name # Lazily load the scaffold generator so a normal `skill-bench run` does # not pull it (and its dependencies) in at boot. require_relative '../rails/skill_templates' content = Rails::SkillTemplates.public_send(template.to_sym, name) File.write(File.join(path, file_name), content) end |
.create_simple_skill(path, name) ⇒ void
This method returns an undefined value.
Create a simple skill with SKILL.md
35 36 37 |
# File 'lib/skill_bench/commands/skill_new.rb', line 35 def self.create_simple_skill(path, name) File.write(File.join(path, 'SKILL.md'), simple_skill_template(name)) end |
.run(name:, mode: 'simple', template: 'service_object') ⇒ void
This method returns an undefined value.
Run the skill new command
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/skill_bench/commands/skill_new.rb', line 15 def self.run(name:, mode: 'simple', template: 'service_object') skill_path = File.join('skills', name) FileUtils.mkdir_p(skill_path) case mode when 'simple' create_simple_skill(skill_path, name) when 'advanced' create_advanced_skill(skill_path, name) when 'rails' create_rails_skill(skill_path, name, template) else raise ArgumentError, "Invalid mode: #{mode}. Use 'simple', 'advanced', or 'rails'." end end |
.simple_skill_template(name) ⇒ String
Generate simple skill template
50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/skill_bench/commands/skill_new.rb', line 50 def self.simple_skill_template(name) <<~MARKDOWN # Skill: #{name} ## Description Add skill description here. ## Context Add context injection content here. ## Workflow Add workflow steps here. MARKDOWN end |