-
Notifications
You must be signed in to change notification settings - Fork 0
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 #292 from code0-tech/272-configuration-settings
Replace env configuration with file configuration
- Loading branch information
Showing
12 changed files
with
137 additions
and
31 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,3 +48,10 @@ | |
*.njsproj | ||
*.sln | ||
*.sw? | ||
|
||
################ | ||
## | ||
## Configuration files | ||
## | ||
################ | ||
config/sagittarius.yml |
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
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
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,17 @@ | ||
rails: | ||
threads: 5 | ||
web: | ||
port: 3000 | ||
force_ssl: | ||
db: | ||
host: localhost | ||
port: 5433 | ||
username: sagittarius | ||
password: sagittarius | ||
encryption: | ||
primary_key: YzaMv4bXYK84unYIQI4Ms4sV3ucbvWs0 | ||
deterministic_key: jgTaxTqzM15ved1S8HdXrqrjfCfF5R0h | ||
key_derivation_salt: Z6zcLTgobXLYjXUslRsLMKxvXKq3j6DJ | ||
secret_key_base: MVMD6CtQwEWrQ28TdokQakbG2FG5abOn | ||
|
||
application_setting_overrides: {} |
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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
version: '3.9' | ||
|
||
services: | ||
postgresql: | ||
postgres: | ||
image: postgres:16.1 | ||
environment: | ||
POSTGRES_USER: "sagittarius" | ||
|
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,45 @@ | ||
# frozen_string_literal: true | ||
|
||
module Sagittarius | ||
class Configuration | ||
extend Sagittarius::Memoize | ||
|
||
def self.config | ||
memoize(:config) do | ||
file_config = YAML.safe_load_file(Rails.root.join('config/sagittarius.yml')).deep_symbolize_keys | ||
defaults.deep_merge(file_config) | ||
rescue Errno::ENOENT # config file does not exist | ||
defaults | ||
end | ||
end | ||
|
||
def self.application_setting_overrides | ||
config[:application_setting_overrides] | ||
end | ||
|
||
def self.defaults | ||
{ | ||
rails: { | ||
threads: 5, | ||
web: { | ||
port: 3000, | ||
force_ssl: nil, | ||
}, | ||
db: { | ||
host: 'localhost', | ||
port: 5433, | ||
username: 'sagittarius', | ||
password: 'sagittarius', | ||
encryption: { | ||
primary_key: 'YzaMv4bXYK84unYIQI4Ms4sV3ucbvWs0', | ||
deterministic_key: 'jgTaxTqzM15ved1S8HdXrqrjfCfF5R0h', | ||
key_derivation_salt: 'Z6zcLTgobXLYjXUslRsLMKxvXKq3j6DJ', | ||
}, | ||
}, | ||
secret_key_base: 'MVMD6CtQwEWrQ28TdokQakbG2FG5abOn', | ||
}, | ||
application_setting_overrides: {}, | ||
} | ||
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,33 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
|
||
RSpec.describe Sagittarius::Configuration do | ||
describe '.config' do | ||
let(:yaml_config) do | ||
<<~CONFIG | ||
rails: | ||
threads: 4 | ||
CONFIG | ||
end | ||
|
||
before do | ||
allow(File).to receive(:open).and_call_original | ||
allow(File).to receive(:open) | ||
.with(Rails.root.join('config/sagittarius.yml'), instance_of(String)) | ||
.and_yield(yaml_config) | ||
described_class.clear_memoize(:config) | ||
end | ||
|
||
it 'loads the config' do | ||
expect(described_class.config).to include(rails: a_hash_including(threads: 4)) | ||
end | ||
end | ||
|
||
describe '.defaults' do | ||
it 'matches the example config' do | ||
example_config = YAML.safe_load_file(Rails.root.join('config/sagittarius.example.yml')).deep_symbolize_keys | ||
expect(example_config).to eq(described_class.defaults) | ||
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,6 @@ | ||
rails: | ||
db: | ||
host: postgres | ||
port: 5432 | ||
web: | ||
force_ssl: false |