to_llm 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 522bcb09f3066274f26eba424d65b7bd520f74e04c55c83f0b0a56640f787b69
4
+ data.tar.gz: 59c1905979d7beae0930d23a465e6ee0b3c6e64a0451fed97c90f90daa6aa566
5
+ SHA512:
6
+ metadata.gz: 6ef6416cc24a686d615add69c851cc1241797f1ef20ec2913fc8c2029296771aef89877c93ab8e9c7a2fb4f4e7e7dfffad9c790249f45593e0c3e02a37665158
7
+ data.tar.gz: 44ce278ed645cec0fbbebb282da7e69a9b87f921643a0c6fac6404b28f68ad37073973ca8102aa044daf117cabb2b33d4a6306472878b1eb749ab332f4e28535
data/README.md ADDED
@@ -0,0 +1,171 @@
1
+ Below is an example of a **README.md** that you might include in your GitHub repository for a gem named **to_llm**. Feel free to adjust any sections (e.g., badges, license, usage details) to match your project’s specifics.
2
+
3
+ ---
4
+
5
+ # to_llm
6
+
7
+ [![Gem Version](https://badge.fury.io/rb/to_llm.svg)](https://badge.fury.io/rb/to_llm)
8
+ [![Build Status](https://github.com/your_user/to_llm/actions/workflows/ci.yml/badge.svg)](https://github.com/your_user/to_llm/actions)
9
+ [![MIT license](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE.txt)
10
+
11
+ **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.
12
+
13
+ ---
14
+
15
+ ## Table of Contents
16
+
17
+ - [Features](#features)
18
+ - [Installation](#installation)
19
+ - [Usage](#usage)
20
+ - [Commands](#commands)
21
+ - [Configuration](#configuration)
22
+ - [Examples](#examples)
23
+ - [Contributing](#contributing)
24
+ - [License](#license)
25
+
26
+ ---
27
+
28
+ ## Features
29
+
30
+ - **Simple extraction**: Automatically scans your Rails app for files in `app/models`, `app/views`, `app/controllers`, etc.
31
+ - **Configurable**: By default, extracts `.rb`, `.erb`, `.js`, and `.yml` file types, but you can easily adjust.
32
+ - **Rake tasks**: Provides a Rake task (`to_llm:extract`) to keep usage straightforward.
33
+ - **Keeps files separate**: Creates separate `.txt` output files (e.g., `models.txt`, `views.txt`) for easier organization (or combine them, if you prefer).
34
+
35
+ ---
36
+
37
+ ## Installation
38
+
39
+ Add this line to your Rails project’s `Gemfile`:
40
+
41
+ ```ruby
42
+ gem 'to_llm', git: 'https://github.com/jcmaciel/to_llm.git'
43
+ ```
44
+
45
+ > Or using RubyGems
46
+ > ```ruby
47
+ > gem 'to_llm'
48
+ > ```
49
+
50
+ Then execute:
51
+
52
+ ```bash
53
+ bundle install
54
+ ```
55
+
56
+ ---
57
+
58
+ ## Usage
59
+
60
+ Once installed, the gem integrates with your Rails app via a Railtie that exposes one or more rake tasks. By default, you can run:
61
+
62
+ ```bash
63
+ rails to_llm:extract -[ALL|MODELS|CONTROLLERS|VIEWS|CONFIG|SCHEMA]
64
+ ```
65
+
66
+ Each of these commands will scan the relevant folders in your Rails app and produce text files containing all the code it finds.
67
+
68
+ ---
69
+
70
+ ## Commands
71
+
72
+ ### 1. `rails to_llm:extract ALL`
73
+
74
+ - **Description**: Extracts from all supported Rails directories:
75
+ - `app/models` -> `models.txt`
76
+ - `app/controllers` -> `controllers.txt`
77
+ - `app/views` -> `views.txt`
78
+ - `app/helpers` -> `helpers.txt`
79
+ - `config` -> `config.txt` (including `config/initializers`)
80
+ - `db/schema.rb` -> `schema.txt`
81
+ - **Result**: Creates a folder named `to_llm/` with separate `.txt` files.
82
+
83
+ ### 2. `rails to_llm:extract MODELS`
84
+
85
+ - **Description**: Extracts only files from `app/models`.
86
+ - **Output**: Creates (or overwrites) `to_llm/models.txt`.
87
+
88
+ ### 3. `rails to_llm:extract CONTROLLERS`
89
+
90
+ - **Description**: Extracts only from `app/controllers`.
91
+ - **Output**: `to_llm/controllers.txt`.
92
+
93
+ ### 4. `rails to_llm:extract VIEWS`
94
+
95
+ - **Description**: Extracts from `app/views`.
96
+ - **Output**: `to_llm/views.txt`.
97
+
98
+ ### 5. `rails to_llm:extract CONFIG`
99
+
100
+ - **Description**: Extracts from `config`, including `config/initializers`.
101
+ - **Output**: `to_llm/config.txt`.
102
+
103
+ ### 6. `rails to_llm:extract SCHEMA`
104
+
105
+ - **Description**: Extracts only `db/schema.rb`.
106
+ - **Output**: `to_llm/schema.txt`.
107
+
108
+ ---
109
+
110
+ ## Configuration
111
+
112
+ 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:
113
+
114
+ ```ruby
115
+ file_extensions = %w[.rb .erb .js .yml]
116
+ directories_to_files = {
117
+ "app/models" => "models.txt",
118
+ "app/controllers" => "controllers.txt",
119
+ # ...
120
+ }
121
+ ```
122
+
123
+ This gem is intentionally minimalist. Feel free to fork or override these settings in your local app.
124
+
125
+ ---
126
+
127
+ ## Examples
128
+
129
+ 1. **Extract everything**:
130
+ ```bash
131
+ rails to_llm:extract -ALL
132
+ ```
133
+ Generates:
134
+ ```
135
+ extracted_files/
136
+ models.txt
137
+ controllers.txt
138
+ views.txt
139
+ helpers.txt
140
+ config.txt
141
+ schema.txt
142
+ ```
143
+
144
+ 2. **Extract only views**:
145
+ ```bash
146
+ rails to_llm:extract -VIEWS
147
+ ```
148
+ Generates:
149
+ ```
150
+ extracted_files/
151
+ views.txt
152
+ ```
153
+ (Note that any previously existing files in `to_llm` will be untouched or overwritten if they have the same filename.)
154
+
155
+ ---
156
+
157
+ ## Contributing
158
+
159
+ 1. Fork the repo on GitHub.
160
+ 2. Create a new branch for your feature (`git checkout -b my-new-feature`).
161
+ 3. Commit your changes (`git commit -am 'Add new feature'`).
162
+ 4. Push to your branch (`git push origin my-new-feature`).
163
+ 5. Create a Pull Request on GitHub.
164
+
165
+ We welcome issues, PRs, and general feedback!
166
+
167
+ ---
168
+
169
+ ## License
170
+
171
+ This project is available as open source under the terms of the [MIT License](./LICENSE.txt). Feel free to use it in your own projects.
@@ -0,0 +1,87 @@
1
+ # frozen_string_literal: true
2
+
3
+ #
4
+ # rails to_llm:extract -ALL
5
+ # rails to_llm:extract -MODELS
6
+ # rails to_llm:extract -CONTROLLERS
7
+ # rails to_llm:extract -VIEWS
8
+ # rails to_llm:extract -CONFIG
9
+ # rails to_llm:extract -SCHEMA
10
+ #
11
+
12
+
13
+ namespace :to_llm do
14
+ desc "Extract code for LLM usage. Usage: rails to_llm:extract [ALL|MODELS|CONTROLLERS|VIEWS|CONFIG|SCHEMA]"
15
+ task :extract, [:type] => :environment do |_t, args|
16
+ # Default to "ALL" if no argument
17
+ extract_type = args[:type]&.upcase || "ALL"
18
+
19
+ puts "----- to_llm:extract started with type=#{extract_type} -----"
20
+
21
+ # Directory where extracted files will be stored
22
+ output_dir = "to_llm"
23
+ FileUtils.mkdir_p(output_dir)
24
+
25
+ # Define which directories to process
26
+ directories_to_files = {
27
+ "app/models" => "models.txt",
28
+ "app/controllers" => "controllers.txt",
29
+ "app/views" => "views.txt",
30
+ "app/helpers" => "helpers.txt",
31
+ "config" => "config.txt",
32
+ "db/schema.rb" => "schema.txt"
33
+ }
34
+
35
+ # We can filter which directories to process based on the user input
36
+ filter_map = {
37
+ "ALL" => %w[app/models app/controllers app/views app/helpers config db/schema.rb],
38
+ "MODELS" => %w[app/models],
39
+ "CONTROLLERS" => %w[app/controllers],
40
+ "VIEWS" => %w[app/views],
41
+ "CONFIG" => %w[config],
42
+ "SCHEMA" => %w[db/schema.rb]
43
+ }
44
+
45
+ # Define which extensions you want to extract
46
+ file_extensions = %w[.rb .erb .js .yml]
47
+
48
+ directories_to_files.values.each do |filename|
49
+ file_path = File.join(output_dir, filename)
50
+ File.delete(file_path) if File.exist?(file_path)
51
+ end
52
+
53
+ def extract_files(dir_path, file_extensions, output_file, output_dir)
54
+ Dir.glob(File.join(dir_path, "**", "*")) do |path|
55
+ next if File.directory?(path)
56
+ next unless file_extensions.include?(File.extname(path))
57
+
58
+ File.open(File.join(output_dir, output_file), "a") do |f|
59
+ f.puts "#{path}:"
60
+ f.puts "----------------------------------------------------"
61
+ f.puts File.read(path)
62
+ f.puts "\n"
63
+ end
64
+ end
65
+ end
66
+
67
+ (filter_map[extract_type] || []).each do |dir_or_file|
68
+ next unless directories_to_files.key?(dir_or_file)
69
+ output_name = directories_to_files[dir_or_file]
70
+
71
+ if File.file?(dir_or_file)
72
+ if File.exist?(dir_or_file)
73
+ File.open(File.join(output_dir, output_name), "a") do |f|
74
+ f.puts "#{dir_or_file}:"
75
+ f.puts "----------------------------------------------------"
76
+ f.puts File.read(dir_or_file)
77
+ f.puts "\n"
78
+ end
79
+ end
80
+ else
81
+ extract_files(dir_or_file, file_extensions, output_name, output_dir)
82
+ end
83
+ end
84
+
85
+ puts "----- to_llm:extract finished! Output is located in '#{output_dir}' -----"
86
+ end
87
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails/railtie'
4
+
5
+ module ToLLM
6
+ class Railtie < ::Rails::Railtie
7
+ railtie_name :to_llm
8
+
9
+ rake_tasks do
10
+ load 'tasks/to_llm.rake'
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ToLLM
4
+ VERSION = "0.1.0"
5
+ end
data/lib/to_llm.rb ADDED
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "to_llm/version"
4
+ require_relative "to_llm/railtie" if defined?(Rails)
5
+
6
+ module ToLLM
7
+ end
metadata ADDED
@@ -0,0 +1,63 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: to_llm
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - José Carlos Maciel
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2024-12-31 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '5.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '5.0'
27
+ description: A simple gem that provides a Rails command or Rake tasks to export .rb,
28
+ .erb, .js, and .yml files into .txt for LLM ingestion.
29
+ email:
30
+ - jcmacielp@gmail.com
31
+ executables: []
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - README.md
36
+ - lib/tasks/to_llm.rake
37
+ - lib/to_llm.rb
38
+ - lib/to_llm/railtie.rb
39
+ - lib/to_llm/version.rb
40
+ homepage: https://github.com/jcmaciel/to_llm
41
+ licenses:
42
+ - MIT
43
+ metadata: {}
44
+ post_install_message:
45
+ rdoc_options: []
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ requirements: []
59
+ rubygems_version: 3.5.11
60
+ signing_key:
61
+ specification_version: 4
62
+ summary: Extracts code from a Rails project to text files for LLM usage.
63
+ test_files: []