From 046dbd03436a82de50dbca64adc3ba908b6fa97c Mon Sep 17 00:00:00 2001 From: nicolasguridi Date: Fri, 21 Apr 2023 11:55:46 -0400 Subject: [PATCH 1/4] feat(assets): add environment variables module file --- lib/potassium/assets/.env.development.erb | 1 + lib/potassium/assets/.env.test.erb | 1 + lib/potassium/assets/lib/environment_variables.rb | 9 +++++++++ lib/potassium/assets/testing/simplecov_config.rb | 1 + 4 files changed, 12 insertions(+) create mode 100644 lib/potassium/assets/.env.test.erb create mode 100644 lib/potassium/assets/lib/environment_variables.rb diff --git a/lib/potassium/assets/.env.development.erb b/lib/potassium/assets/.env.development.erb index 522a3961..0c795752 100644 --- a/lib/potassium/assets/.env.development.erb +++ b/lib/potassium/assets/.env.development.erb @@ -5,3 +5,4 @@ DEFAULT_EMAIL_ADDRESS= EXECJS_RUNTIME=Node SECRET_KEY_BASE=development_secret WEB_CONCURRENCY=1 +APPLICATION_HOST=localhost:3000 diff --git a/lib/potassium/assets/.env.test.erb b/lib/potassium/assets/.env.test.erb new file mode 100644 index 00000000..5d91fbfc --- /dev/null +++ b/lib/potassium/assets/.env.test.erb @@ -0,0 +1 @@ +APPLICATION_HOST=localhost:3000 diff --git a/lib/potassium/assets/lib/environment_variables.rb b/lib/potassium/assets/lib/environment_variables.rb new file mode 100644 index 00000000..1932cfab --- /dev/null +++ b/lib/potassium/assets/lib/environment_variables.rb @@ -0,0 +1,9 @@ +module EnvironmentVariables + extend self + + APPLICATION_HOST = ENV.fetch('APPLICATION_HOST') + + def application_host + APPLICATION_HOST + end +end diff --git a/lib/potassium/assets/testing/simplecov_config.rb b/lib/potassium/assets/testing/simplecov_config.rb index 45acac8e..307a36ef 100644 --- a/lib/potassium/assets/testing/simplecov_config.rb +++ b/lib/potassium/assets/testing/simplecov_config.rb @@ -49,6 +49,7 @@ add_filter 'app/responders' add_filter 'lib/fake_data_loader.rb' add_filter 'lib/vue_component.rb' + add_filter 'lib/environment_variables.rb' if ENV["CIRCLECI"] formatter( From 1100063813295c3826925610a019be6342979d4a Mon Sep 17 00:00:00 2001 From: nicolasguridi Date: Fri, 21 Apr 2023 11:57:37 -0400 Subject: [PATCH 2/4] feat(recipes): create environment variables recipe --- .../recipes/environment_variables.rb | 18 +++++++++++++++ lib/potassium/templates/application.rb | 1 + spec/features/environment_variables_spec.rb | 22 +++++++++++++++++++ 3 files changed, 41 insertions(+) create mode 100644 lib/potassium/recipes/environment_variables.rb create mode 100644 spec/features/environment_variables_spec.rb diff --git a/lib/potassium/recipes/environment_variables.rb b/lib/potassium/recipes/environment_variables.rb new file mode 100644 index 00000000..6cb78df8 --- /dev/null +++ b/lib/potassium/recipes/environment_variables.rb @@ -0,0 +1,18 @@ +class Recipes::EnvironmentVariables < Rails::AppBuilder + def create + template '../assets/.env.test.erb', '.env.test' + copy_file '../assets/lib/environment_variables.rb', 'lib/environment_variables.rb' + + application(before_configuration_require) + end + + private + + def before_configuration_require + <<~RUBY + config.before_configuration do + require Rails.root.join('lib/environment_variables.rb') + end + RUBY + end +end diff --git a/lib/potassium/templates/application.rb b/lib/potassium/templates/application.rb index 47a6e0cb..312f212d 100644 --- a/lib/potassium/templates/application.rb +++ b/lib/potassium/templates/application.rb @@ -74,6 +74,7 @@ create :front_end_vite create :admin create :vue_admin + create :environment_variables end info "Gathered enough information. Applying the template. Wait a minute." diff --git a/spec/features/environment_variables_spec.rb b/spec/features/environment_variables_spec.rb new file mode 100644 index 00000000..fedf1f6b --- /dev/null +++ b/spec/features/environment_variables_spec.rb @@ -0,0 +1,22 @@ +require 'spec_helper' + +RSpec.describe 'EnvironmentVariables' do + let(:environment_variables) { IO.read("#{project_path}/lib/environment_variables.rb") } + + it 'creates a .env.test file' do + expect(File.exists?("#{project_path}/.env.test")).to eq(true) + end + + it 'creates an EnvironmentVariables module with a constant and its method' do + expect(environment_variables).to include( + 'module EnvironmentVariables', + "APPLICATION_HOST = ENV.fetch('APPLICATION_HOST')", + 'def application_host' + ) + end + + it 'requires module in application configuration' do + expect(File.read("#{project_path}/config/application.rb")) + .to include("require Rails.root.join('lib/environment_variables.rb')") + end +end From 0ccbeb7b4edcb7e46b6bae88bb7b9397f0f2ffda Mon Sep 17 00:00:00 2001 From: nicolasguridi Date: Fri, 21 Apr 2023 12:00:22 -0400 Subject: [PATCH 3/4] docs(): fix typos in contributing file --- docs/CONTRIBUTING.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/CONTRIBUTING.md b/docs/CONTRIBUTING.md index 8f4be843..17f9d74a 100644 --- a/docs/CONTRIBUTING.md +++ b/docs/CONTRIBUTING.md @@ -14,13 +14,13 @@ Now, to add some behavior, thanks to the [DSL](/docs/DSL.md) we have a kind of s 4. Install the gems, filling the `Gemfile` before with all the gathered gems. 5. Finally, create the database. -The main step is the 3rd, when we call the `create` methods from the recipes. A recipe can do anything (because is a ruby script) but their responsability should be to gather gems and register callbacks for the process. +The main step is the 3rd, when we call the `create` methods from the recipes. A recipe can do anything (because is a ruby script) but their responsibility should be to gather gems and register callbacks for the process. ### Recipe The recipes are classes defined in the `Recipes` module that inherit from `Rails::AppBuilder` and by convention can implement some of the following -methods `ask`, `create` and `install`. So they took this form. +methods `ask`, `create` and `install`. They take this form. ```ruby class Recipes::MyRecipe < Rails::AppBuilder @@ -73,7 +73,7 @@ This method is used if you need to ask something to the user before doing someth We'll call this method to add specific functionality to the rails project. -1. In the `create` method register a gem using `gather_gem` and create a callback to be called after the `gem_install` action succeded to run the generator. `gem_install` is one of the main actions that should be easily visible with a sneak peek in [the template][the-template]. +1. In the `create` method register a gem using `gather_gem` and create a callback to be called after the `gem_install` action succeeds to run the generator. `gem_install` is one of the main actions that should be easily visible with a sneak peek in [the template][the-template]. ```ruby def create @@ -99,8 +99,8 @@ We'll call this method to add specific functionality to the rails project. ##### | `install` The install method will be called when you use the `install` command from potassium. -For example if you run `portassium install devise` this will use -[the recipe template](/lib/potassium/templates/recipe.rb) to load an execute the +For example, if you run `potassium install devise` this will use +[the recipe template](/lib/potassium/templates/recipe.rb) to load and execute the `install` method for the **devise** recipe. You can define the main functionallity of a recipe in a private method and call @@ -127,6 +127,6 @@ end To see further documentation of what we added to the rails template's DSL, check the [DSL documentation](/docs/DSL.md). -> Remember that the DSL we are documenting is an extension over the [Rails Application Template DSL](http://edgeguides.rubyonrails.org/rails_application_templates.html), that itself is a dsl based on [Thor](https://github.com/erikhuda/thor/wiki). +> Remember that the DSL we are documenting is an extension over the [Rails Application Template DSL](http://edgeguides.rubyonrails.org/rails_application_templates.html), that itself is a DSL based on [Thor](https://github.com/erikhuda/thor/wiki). [the-template]: /lib/potassium/templates/application.rb From b640ef48f6f3970288669120787a23cd423b7ae5 Mon Sep 17 00:00:00 2001 From: nicolasguridi Date: Fri, 21 Apr 2023 14:24:47 -0400 Subject: [PATCH 4/4] docs(): update changelog --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3da1407f..424cd961 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ # Changelog ## Unreleased +Features + - Add environment variables module recipe [#435](https://github.com/platanus/potassium/pull/435) + +Fixes + - Fix CircleCI config [#434](https://github.com/platanus/potassium/pull/434) ## 7.0.0