Project

to_llm

0.0
The project is in a healthy, maintained state
A simple gem that provides a Rails command or Rake tasks to export .rb, .erb, .js, and .yml files into .txt for LLM ingestion.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Runtime

>= 5.0
 Project Readme

to_llm

Gem Version MIT license

to_llm is a lightweight Ruby gem that provides a simple set of tasks (or commands) to extract code from a Rails application into text files. This is useful if you want to feed your Rails codebase into a Large Language Model (LLM) or any text-based analysis tool.


Table of Contents

  • Features
  • Installation
  • Usage
  • Commands
  • Configuration
  • Examples
  • Contributing
  • License

Features

  • Simple extraction: Automatically scans your Rails app for files in app/models, app/views, app/controllers, etc.
  • Configurable: By default, extracts .rb, .erb, .js, and .yml file types, but you can easily adjust.
  • Rake tasks: Provides a Rake task (to_llm:extract) to keep usage straightforward.
  • Keeps files separate: Creates separate .txt output files (e.g., models.txt, views.txt) for easier organization (or combine them, if you prefer).

Installation

Add this line to your Rails project’s Gemfile:

gem 'to_llm', git: 'https://github.com/jcmaciel/to_llm.git'

Or using RubyGems

gem 'to_llm'

Then execute:

bundle install

Usage

Once installed, the gem integrates with your Rails app via a Railtie that exposes one or more rake tasks. By default, you can run:

rails to_llm:extract -[ALL|MODELS|CONTROLLERS|VIEWS|CONFIG|SCHEMA|JAVASCRIPT]

Each of these commands will scan the relevant folders in your Rails app and produce text files containing all the code it finds.


Commands

1. rails to_llm:extract -ALL

  • Description: Extracts from all supported Rails directories:
    • app/models -> models.txt
    • app/controllers -> controllers.txt
    • app/views -> views.txt
    • app/helpers -> helpers.txt
    • config -> config.txt (including config/initializers)
    • db/schema.rb -> schema.txt
    • app/javascript -> javascript.txt
  • Result: Creates a folder named to_llm/ with separate .txt files.

2. rails to_llm:extract -MODELS

  • Description: Extracts only files from app/models.
  • Output: Creates (or overwrites) to_llm/models.txt.

3. rails to_llm:extract -CONTROLLERS

  • Description: Extracts only from app/controllers.
  • Output: to_llm/controllers.txt.

4. rails to_llm:extract -VIEWS

  • Description: Extracts from app/views.
  • Output: to_llm/views.txt.

5. rails to_llm:extract -CONFIG

  • Description: Extracts from config, including config/initializers.
  • Output: to_llm/config.txt.

6. rails to_llm:extract -SCHEMA

  • Description: Extracts only db/schema.rb.
  • Output: to_llm/schema.txt.

7. rails to_llm:extract -JAVASCRIPT

  • Description: Extracts only from app/javascript.
  • Output: to_llm/javascript.txt.

8. rails to_llm:extract -HELPERS

  • Description: Extracts only from app/helpers.
  • Output: to_llm/helpers.txt.

Configuration

If you want to customize what extensions are included or which directories map to which output files, open the lib/tasks/to_llm.rake file (inside this gem) and edit:

file_extensions = %w[.rb .erb .js .yml]
directories_to_files = {
  "app/models"      => "models.txt",
  "app/controllers" => "controllers.txt",
  # ...
}

This gem is intentionally minimalist. Feel free to fork or override these settings in your local app.


Examples

  1. Extract everything:

    rails to_llm:extract -ALL

    Generates:

    to_llm/
      models.txt
      controllers.txt
      views.txt
      helpers.txt
      config.txt
      schema.txt
      javascript.txt
    
  2. Extract only views:

    rails to_llm:extract -VIEWS

    Generates:

    to_llm/
      views.txt
    

    (Note that any previously existing files in to_llm will be untouched or overwritten if they have the same filename.)


Contributing

  1. Fork the repo on GitHub.
  2. Create a new branch for your feature (git checkout -b my-new-feature).
  3. Commit your changes (git commit -am 'Add new feature').
  4. Push to your branch (git push origin my-new-feature).
  5. Create a Pull Request on GitHub.

We welcome issues, PRs, and general feedback!


License

This project is available as open source under the terms of the MIT License. Feel free to use it in your own projects.