Last active
October 14, 2025 06:21
-
-
Save overdrivemachines/1c4cac1519ad0215e2aa5d41d3af1016 to your computer and use it in GitHub Desktop.
template.rb - Ruby on Rails Template
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'net/http' | |
| require 'uri' | |
| # === Remove Comments in Gemfile === | |
| # Path to the Gemfile | |
| gemfile_path = 'Gemfile' | |
| # Read the content of the Gemfile | |
| gemfile_content = File.read(gemfile_path) | |
| # Remove comments from the Gemfile | |
| gemfile_content.gsub!(/^#.*$/, '') | |
| # Remove the entire development group | |
| gemfile_content.gsub!( | |
| /group :development do\n.*\nend\n/m, | |
| '' | |
| ) | |
| # Remove the entire development/test group | |
| gemfile_content.gsub!( | |
| /group :development, :test do\n.*\nend\n/m, | |
| '' | |
| ) | |
| # Remove the empty lines | |
| gemfile_content.gsub!(/^\s*\n/, '') | |
| # Write the modified content back to the Gemfile | |
| File.write(gemfile_path, gemfile_content) | |
| # === Add gems === | |
| # gem 'sassc-rails' | |
| gem "image_processing", "~> 1.2" | |
| gem_group :development do | |
| gem "web-console" # Use console on exceptions pages | |
| gem "letter_opener" # Preview emails in the browser instead of sending | |
| gem "rails-erd" # Entity-Relationship Diagrams | |
| gem "chusaku", require: false # Annotate controllers | |
| gem "annotate" # Annotate models, routes, factories, and fixtures | |
| end | |
| gem_group :development, :test do | |
| gem "debug", platforms: %i[ mri windows ], require: "debug/prelude" | |
| gem "brakeman", require: false # Static analysis for security vulnerabilities | |
| gem "rubocop-rails-omakase", require: false # Omakase Ruby styling | |
| gem "faker" # Generate fake data such as names, addresses, and phone numbers | |
| gem "rspec-rails" # RSpec for Rails | |
| gem "factory_bot_rails" # Create test data | |
| gem "simplecov", require: false # Code coverage analysis | |
| end | |
| run 'bundle install' | |
| # === ERD (Entity Relationship Diagram) .erdconfig === | |
| erdconfig_content = <<~ERDCONFIG | |
| attributes: content,foreign_key | |
| filetype: png | |
| ERDCONFIG | |
| File.write('.erdconfig', erdconfig_content) | |
| run 'bundle exec rails g erd:install' | |
| # === Prettier Config .prettierrc === | |
| prettier_config_content = <<~PRETTIERCONFIG | |
| { | |
| "printWidth": 250 | |
| } | |
| PRETTIERCONFIG | |
| File.write('.prettierrc', prettier_config_content) | |
| # === Annotate Models and Routes file === | |
| run 'curl -LJ --output lib/tasks/routes.rake https://gist.githubusercontent.com/overdrivemachines/18ab18a986f1db4ec1fe6fbfb37b90ba/raw/fccd6a35595ce38531d1ea01cf623a3d65def141/routes.rake' | |
| run 'rails g annotate:install' | |
| # === Add edit_credentials.sh === | |
| run 'curl -LJ --output edit_credentials.sh https://gist.githubusercontent.com/overdrivemachines/ee84107bdbd881b692a811b4d5c2093c/raw/66fe073734cdf9a6b51489ff347e838d42d61d8d/edit_credentials.sh' | |
| run 'chmod +x edit_credentials.sh' # Add execute permissions | |
| # === Email Configuration === | |
| # Add custom configuration to development.rb inside the configure block | |
| development_config_content = <<~DEVELOPMENTCONFIG | |
| # Custom configuration for development environment | |
| host = "localhost:3000" | |
| config.action_mailer.default_url_options = { host: host, protocol: 'http' } | |
| # letter_opener gem configuration: https://github.com/ryanb/letter_opener | |
| # Now any email will pop up in your browser instead of being sent. | |
| config.action_mailer.delivery_method = :letter_opener | |
| config.action_mailer.perform_deliveries = true | |
| DEVELOPMENTCONFIG | |
| # Update development.rb to insert custom configuration inside the existing configure block | |
| development_rb_path = 'config/environments/development.rb' | |
| development_rb_content = File.read(development_rb_path) | |
| development_rb_content.gsub!( | |
| /(Rails\.application\.configure do\s*\n)/, | |
| "\\1#{development_config_content}" | |
| ) | |
| # Write the modified content back to development.rb | |
| File.write(development_rb_path, development_rb_content) | |
| # === README.md file === | |
| # Path to the README.md file | |
| readme_file_path = 'README.md' | |
| # Define the content to replace README.md | |
| readme_content = <<~MARKDOWN | |
| # App Name | |
|  | |
| # Features | |
| # Model | |
| Generated by Rails ERD. Run rails erd to regenerate (must have graphviz). | |
|  | |
| ## Version | |
| - #{`ruby -v`.strip} | |
| - #{`rails -v`.strip} | |
| ## What I Learned | |
| ## References | |
| MARKDOWN | |
| # Write the new content to the README.md file | |
| File.write(readme_file_path, readme_content) | |
| # === Git commit ==== | |
| # Add a block to run after bundling gems | |
| after_bundle do | |
| git :init | |
| git add: '.' | |
| git commit: "-a -m 'Initial commit'" | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment