Code generation engine for LegionIO extensions. Scaffolds complete lex-* gem trees from scratch, renders individual ERB templates, validates existing extension structure, and generates companion RSpec files. Used by the legion lex create CLI command and by agentic swarm pipelines.
Add to your Gemfile or gemspec:
gem'lex-codegen'Or install directly:
gem install lex-codegenrequire'legion/extensions/codegen'client=Legion::Extensions::Codegen::Client.new(base_path: '/path/to/output')result=client.scaffold_extension(name: 'myextension',module_name: 'Myextension',description: 'Does something useful',helpers: ['config'],runner_methods: [{name: 'run_job',params: ['job_id:']},{name: 'check_status',params: ['job_id:','verbose: false']}])result[:success]# => trueresult[:path]# => '/path/to/output/lex-myextension'result[:files_created]# => 15This writes a fully structured gem including gemspec, Gemfile, .rubocop.yml, GitHub Actions CI workflow, .rspec, .gitignore, LICENSE, version.rb, entry point, client, helpers, runners, and RSpec files for all of the above.
result=client.generate_file(template_type: :runner,output_path: '/tmp/myrunner.rb',variables: {module_name: 'Myextension',gem_name_underscored: 'myextension',runner_class: 'RunJob',methods: [{name: 'run_job',params: ['job_id:']}]})result[:bytes]# => number of bytes writtenrunner=Legion::Extensions::Codegen::Runners::Templatecontent=runner.render_template(template_type: :version,variables: {module_name: 'Myextension',gem_version: '0.1.0'})putscontent[:content]# frozen_string_literal: true# module Legion::Extensions::Myextension; VERSION = '0.1.0'; endrunner.list_templates# => { success: true, templates: [:gemspec, :gemfile, :rubocop, :ci, :rspec, :gitignore,# :license, :version, :entry_point, :spec_helper, :runner, :client] }runner.template_variables(template_type: :gemspec)# => { success: true, template_type: :gemspec,# required_variables: [:gem_name, :module_name, :description, :author, :email,# :ruby_version, :license, :extra_deps] }validator=Legion::Extensions::Codegen::Runners::Validate# Check directory structurevalidator.validate_structure(path: '/path/to/lex-myextension')# => { valid: true, missing: [], present: ['Gemfile', '.rubocop.yml', ...] }# Check rubocop configvalidator.validate_rubocop_config(path: '/path/to/lex-myextension')# => { valid: true, issues: [] }# Check gemspec fieldsvalidator.validate_gemspec(path: '/path/to/lex-myextension')# => { valid: true, issues: [], path: '/path/to/lex-myextension/lex-myextension.gemspec' }spec_gen=Legion::Extensions::Codegen::Helpers::SpecGenerator.new# Runner specputsspec_gen.generate_runner_spec(module_name: 'Myextension',runner_name: 'run_job',methods: [{name: 'run_job',params: ['job_id:']}])# Client specputsspec_gen.generate_client_spec(module_name: 'Myextension')# Helper specputsspec_gen.generate_helper_spec(module_name: 'Myextension',helper_name: 'config',methods: [{name: 'load',params: []}])| Template | Generates |
|---|---|
gemspec | lex-name.gemspec |
gemfile | Gemfile with gemspec + test group |
rubocop | .rubocop.yml with LegionIO defaults |
ci | .github/workflows/ci.yml (calls shared reusable workflow) |
rspec | .rspec with --format documentation |
gitignore | .gitignore with standard Ruby entries |
license | LICENSE (MIT) |
version | lib/legion/extensions/<name>/version.rb |
entry_point | lib/legion/extensions/<name>.rb |
spec_helper | spec/spec_helper.rb with Legion::Logging stub |
runner | One runner module with stubbed methods |
client | Client class including runner modules |
| Setting | Default |
|---|---|
| Ruby version | 3.4 |
| License | MIT |
| Author | Esity |
matthewdiverson@gmail.com | |
| Gem version | 0.1.0 |
bundle install
bundle exec rspec
bundle exec rubocopMIT. See LICENSE.