Skip to content

Commit

Permalink
Merge pull request #105 from TruemarkDev/generator-for-dotenv
Browse files Browse the repository at this point in the history
Generator for dotenv
  • Loading branch information
abhaynikam authored May 31, 2024
2 parents cd66e7e + 8b8eaaf commit 868e729
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* Adds Doorkeeper Generator with Devise. ([@TheZero0-ctrl][])
* Adds Avo generator. ([@mausamp][])
* Adds Sentry generator. ([@mausamp][])
* Adds Dotenv generator. ([@mausamp][])

## 0.13.0 (March 26th, 2024)
* Adds Letter Opener generator. ([@coolprobn][])
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ The boring generator introduces following generators:
- Install Avo: `rails generate boring:avo:install`
- Install Doorkeeper with devise: `rails generate boring:devise:doorkeeper:install`
- Install Sentry: `rails generate boring:sentry:install --use_env_variable --breadcrumbs_logger=<breadcrumbs_logger_options>`
- Install Dotenv: `rails generate boring:dotenv:install`

## Screencasts

Expand Down
31 changes: 31 additions & 0 deletions lib/generators/boring/dotenv/install/install_generator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# frozen_string_literal: true

module Boring
module Dotenv
class InstallGenerator < Rails::Generators::Base
desc 'Adds dotenv gem to the application'
source_root File.expand_path("templates", __dir__)

def add_dotenv_gem
say 'Adding dotenv gem', :green

Bundler.with_unbundled_env do
run 'bundle add dotenv-rails --group development'
end
end

def configure_dotenv_gem
say 'Configuring dotenv gem', :green

template '.env', '.env'

unless File.exist?('.gitignore')
create_file '.gitignore'
end

FileUtils.cp('.env', '.env.sample')
insert_into_file('.gitignore', "\n/.env\n")
end
end
end
end
3 changes: 3 additions & 0 deletions lib/generators/boring/dotenv/install/templates/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Add your environment variables here
# Example:
# SECRET_KEY_BASE=your_secret_key
35 changes: 35 additions & 0 deletions test/generators/dotenv_install_generator_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# frozen_string_literal: true

require 'test_helper'
require 'generators/boring/dotenv/install/install_generator'

class DotenvInstallGeneratorTest < Rails::Generators::TestCase
tests Boring::Dotenv::InstallGenerator
setup :build_app
teardown :teardown_app

include GeneratorHelper

def destination_root
app_path
end

def test_should_install_dotenv_gem
Dir.chdir(app_path) do
quietly { run_generator }

assert_gem 'dotenv-rails'

assert_file '.env' do |content|
assert_match(/# Add your environment variables here/, content)
assert_match(/# SECRET_KEY_BASE=your_secret_key/, content)
end

assert_file '.env.sample'

assert_file '.gitignore' do |content|
assert_match(/.env/, content)
end
end
end
end

0 comments on commit 868e729

Please sign in to comment.