Skip to content

Commit

Permalink
Merged in feature/integrate_dotenv_rails_gem (pull request #10)
Browse files Browse the repository at this point in the history
Feature/integrate dotenv rails gem

Approved-by: Fatih Avsan <fatih.avsan@lab2023.com>
Approved-by: Hamdi Bayhan <hamdi.bayhan@lab2023.com>
  • Loading branch information
Eşref VİDUŞLU authored and İsmail Akbudak committed Oct 31, 2017
2 parents 8c6675e + a6554e5 commit 0806df7
Show file tree
Hide file tree
Showing 12 changed files with 97 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/cybele.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@
require 'cybele/helpers/recipient_interceptor'
require 'cybele/helpers/haml'
require 'cybele/helpers/locale_language'
require 'cybele/helpers/dotenv'
require 'cybele/app_builder'
1 change: 1 addition & 0 deletions lib/cybele/app_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class AppBuilder < Rails::AppBuilder
include Cybele::Helpers::ShowFor
include Cybele::Helpers::Haml
include Cybele::Helpers::LocaleLanguage
include Cybele::Helpers::Dotenv

def readme
template 'README.md.erb',
Expand Down
5 changes: 5 additions & 0 deletions lib/cybele/generators/app_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,11 @@ def add_staging_secret_key
build :add_staging_secret_key_to_secrets_yml
end

def setup_dotenv
say 'Generate env.sample and .env files', :green
build :configure_dotenv
end

def goodbye
say 'Congratulations! That\'s all...', :green
end
Expand Down
28 changes: 28 additions & 0 deletions lib/cybele/helpers/dotenv.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# frozen_string_literal: true

module Cybele
module Helpers
module Dotenv
def configure_dotenv
# Add dotenv gem
inject_into_file 'Gemfile', template_content('dotenv/dotenv_Gemfile.erb'),
before: "# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'"
run_bundle

# Create dotenv files
template 'dotenv/env.sample.erb',
'env.sample',
force: true
template 'dotenv/.env.local.erb',
'.env.local',
force: true
template 'dotenv/.env.staging.erb',
'.env.staging',
force: true
template 'dotenv/.env.production.erb',
'.env.production',
force: true
end
end
end
end
21 changes: 21 additions & 0 deletions spec/features/new_default_project_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,27 @@
expect(secret_file).to match('staging')
end

it 'control env.sample and .env files' do
gemfile_file = content('Gemfile')
expect(gemfile_file).to match(/^gem 'dotenv-rails'/)

expect(File).to exist(file_project_path('env.sample'))
env_sample_file = content('env.sample')
expect(env_sample_file).to match('ROOT_PATH=http://localhost:3000')

expect(File).to exist(file_project_path('.env.local'))
env_local_file = content('.env.local')
expect(env_local_file).to match('ROOT_PATH=http://localhost:3000')

expect(File).to exist(file_project_path('.env.staging'))
env_staging_file = content('.env.staging')
expect(env_staging_file).to match('ROOT_PATH=https://staging-dummy_app.herokuapp.com')

expect(File).to exist(file_project_path('.env.production'))
env_production_file = content('.env.production')
expect(env_production_file).to match('ROOT_PATH=https://dummy_app.herokuapp.com')
end

it 'uses haml' do
gemfile_file = content('Gemfile')
expect(gemfile_file).to match(/^gem 'haml'/)
Expand Down
21 changes: 21 additions & 0 deletions spec/features/new_not_default_project_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,27 @@
expect(secret_file).to match('staging')
end

it 'control env.sample and .env files' do
gemfile_file = content('Gemfile')
expect(gemfile_file).to match(/^gem 'dotenv-rails'/)

expect(File).to exist(file_project_path('env.sample'))
env_sample_file = content('env.sample')
expect(env_sample_file).to match('ROOT_PATH=http://localhost:3000')

expect(File).to exist(file_project_path('.env.local'))
env_local_file = content('.env.local')
expect(env_local_file).to match('ROOT_PATH=http://localhost:3000')

expect(File).to exist(file_project_path('.env.staging'))
env_staging_file = content('.env.staging')
expect(env_staging_file).to match('ROOT_PATH=https://staging-dummy_app.herokuapp.com')

expect(File).to exist(file_project_path('.env.production'))
env_production_file = content('.env.production')
expect(env_production_file).to match('ROOT_PATH=https://dummy_app.herokuapp.com')
end

it 'do not use haml' do
gemfile_file = content('Gemfile')
expect(gemfile_file).not_to match(/^gem 'haml'/)
Expand Down
3 changes: 3 additions & 0 deletions templates/dotenv/.env.local.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ROOT_PATH=http://localhost:3000

ROLLBAR_ACCESS_TOKEN=
5 changes: 5 additions & 0 deletions templates/dotenv/.env.production.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ROOT_PATH=https://<%= app_name %>.herokuapp.com

ROLLBAR_ACCESS_TOKEN=

SECRET_KEY_BASE=
5 changes: 5 additions & 0 deletions templates/dotenv/.env.staging.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ROOT_PATH=https://staging-<%= app_name %>.herokuapp.com

ROLLBAR_ACCESS_TOKEN=

SECRET_KEY_BASE=
2 changes: 2 additions & 0 deletions templates/dotenv/dotenv_Gemfile.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Dot-Env
gem 'dotenv-rails', require: 'dotenv/rails-now'
3 changes: 3 additions & 0 deletions templates/dotenv/env.sample.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ROOT_PATH=http://localhost:3000

ROLLBAR_ACCESS_TOKEN=
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
Mail.register_interceptor RecipientInterceptor.new(Settings.email.sandbox, subject_prefix: '[STAGING]')

Mail.register_interceptor RecipientInterceptor.new(Settings.email.sandbox, subject_prefix: '[STAGING]')

0 comments on commit 0806df7

Please sign in to comment.