-
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #105 from TruemarkDev/generator-for-dotenv
Generator for dotenv
- Loading branch information
Showing
5 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
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 |
This file contains 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
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 |
This file contains 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
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 |