autocontext 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +49 -0
- data/lib/autocontext/railtie.rb +14 -0
- data/lib/autocontext/version.rb +3 -0
- data/lib/autocontext.rb +59 -0
- metadata +64 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 8472002850013e566e7f0bce46de4af70da247fff7e767dd427e251b317b7773
|
4
|
+
data.tar.gz: adda6e190b5a910060f23f3afb8ae774d682b73cc31001eecb7f5c91beeb44ec
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b262dad39ef7094be984e2ee302021c249d727ebe6adbe0410aef85c919dc7d97bf4e34bf59af876a6f46c954c364e7f53289eefd285128bc0b3c335a3af26a5
|
7
|
+
data.tar.gz: c2e3823ac9b8dcc02c7211c5a3a6c43c1920ffb190518cf6aba75b780dbcd065c930e2dc3202ed795cf6e920d2194940e4f11b3baa43a6898eac11b828994689
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright Bill Tihen
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# Autocontext
|
2
|
+
|
3
|
+
Autocontext is a Ruby gem that automatically generates a context file containing information about your Rails application's models, controllers, and environment.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'autocontext'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle install
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install autocontext
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
To generate the autocontext file, run:
|
24
|
+
|
25
|
+
```bash
|
26
|
+
rake autocontext:generate
|
27
|
+
```
|
28
|
+
|
29
|
+
This will create a `.autocontext` file in your Rails application's root directory containing:
|
30
|
+
- Ruby and Rails versions
|
31
|
+
- List of controllers
|
32
|
+
- List of models with their:
|
33
|
+
- Table names
|
34
|
+
- File paths
|
35
|
+
- Associations
|
36
|
+
|
37
|
+
## Development
|
38
|
+
|
39
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
40
|
+
|
41
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
42
|
+
|
43
|
+
## Contributing
|
44
|
+
|
45
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/yourusername/autocontext.
|
46
|
+
|
47
|
+
## License
|
48
|
+
|
49
|
+
The gem is available as open source under the terms of the MIT License.
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'rails'
|
2
|
+
|
3
|
+
module Autocontext
|
4
|
+
class Railtie < Rails::Railtie
|
5
|
+
rake_tasks do
|
6
|
+
namespace :autocontext do
|
7
|
+
desc "Generate the autocontext file"
|
8
|
+
task generate: :environment do
|
9
|
+
Autocontext::Generator.generate
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/lib/autocontext.rb
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
require "autocontext/version"
|
2
|
+
require "autocontext/railtie" if defined?(Rails)
|
3
|
+
|
4
|
+
module Autocontext
|
5
|
+
class Error < StandardError; end
|
6
|
+
|
7
|
+
class Generator
|
8
|
+
def self.generate
|
9
|
+
# Check if Rails is defined
|
10
|
+
raise "Rails is not defined. Please ensure you are running this within a Rails application." unless defined?(Rails)
|
11
|
+
|
12
|
+
puts "Generating autocontext file"
|
13
|
+
|
14
|
+
Rails.application.eager_load!
|
15
|
+
|
16
|
+
gemfile_content = File.read(Rails.root.join('Gemfile'))
|
17
|
+
|
18
|
+
ruby_version = gemfile_content.match(/ruby ['"](.+?)['"]/i)&.captures&.first
|
19
|
+
rails_version = gemfile_content.match(/gem ['"]rails['"],\s*['"](.+?)['"]/i)&.captures&.first
|
20
|
+
|
21
|
+
File.open('.autocontext', 'w') do |file|
|
22
|
+
file.puts "/* AutoContext generation completed at #{Time.now} */"
|
23
|
+
file.puts "Ruby version: #{ruby_version}"
|
24
|
+
file.puts "Rails version: #{rails_version}"
|
25
|
+
file.puts ""
|
26
|
+
self.generate_controllers(file)
|
27
|
+
file.puts ""
|
28
|
+
file.puts "Models:"
|
29
|
+
ApplicationRecord.descendants.each do |model|
|
30
|
+
file.puts " #{model.name}:"
|
31
|
+
file.puts " superclass: #{model.superclass.name}"
|
32
|
+
file.puts " database: #{model.connection.current_database}"
|
33
|
+
file.puts " table_name: #{model.table_name}"
|
34
|
+
file.puts " relative path: app/models/#{model.name.underscore}.rb"
|
35
|
+
|
36
|
+
self.generate_associations(model, file)
|
37
|
+
file.puts ""
|
38
|
+
|
39
|
+
rescue => e
|
40
|
+
puts "Error generating autocontext for #{model.name}: #{e.message}"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.generate_controllers(file)
|
46
|
+
file.puts "Controllers:"
|
47
|
+
file.puts " - #{ApplicationController.descendants.map(&:name).join(", ")}"
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.generate_associations(model, file)
|
51
|
+
file.puts " associations:"
|
52
|
+
model.reflect_on_all_associations.each do |association|
|
53
|
+
file.puts " - #{association.macro} #{association.name} #{association.foreign_key} #{association.polymorphic? ? "polymorphic" : ""} (#{association.class_name})"
|
54
|
+
rescue => e
|
55
|
+
puts "Error generating associations for #{model.name}: #{e.message}"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
metadata
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: autocontext
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Caleb LeNoir
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-11-15 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: '6.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '6.0'
|
27
|
+
description: A Ruby gem that generates a context file containing information about
|
28
|
+
your Rails application's models, controllers, and environment
|
29
|
+
email:
|
30
|
+
- caleb.lenoir@hey.com
|
31
|
+
executables: []
|
32
|
+
extensions: []
|
33
|
+
extra_rdoc_files: []
|
34
|
+
files:
|
35
|
+
- MIT-LICENSE
|
36
|
+
- README.md
|
37
|
+
- lib/autocontext.rb
|
38
|
+
- lib/autocontext/railtie.rb
|
39
|
+
- lib/autocontext/version.rb
|
40
|
+
homepage: https://github.com/calebl/autocontext
|
41
|
+
licenses:
|
42
|
+
- MIT
|
43
|
+
metadata:
|
44
|
+
allowed_push_host: https://rubygems.org
|
45
|
+
post_install_message:
|
46
|
+
rdoc_options: []
|
47
|
+
require_paths:
|
48
|
+
- lib
|
49
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 2.6.0
|
54
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: '0'
|
59
|
+
requirements: []
|
60
|
+
rubygems_version: 3.5.16
|
61
|
+
signing_key:
|
62
|
+
specification_version: 4
|
63
|
+
summary: Automatically generate context files for Rails applications
|
64
|
+
test_files: []
|