to_llm
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
(includingconfig/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
, includingconfig/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
-
Extract everything:
rails to_llm:extract -ALL
Generates:
to_llm/ models.txt controllers.txt views.txt helpers.txt config.txt schema.txt javascript.txt
-
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
- Fork the repo on GitHub.
- Create a new branch for your feature (
git checkout -b my-new-feature
). - Commit your changes (
git commit -am 'Add new feature'
). - Push to your branch (
git push origin my-new-feature
). - 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.