Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added config.prepend_sources option to Config.setup #142

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,10 @@ Settings.path

### Environment variables

Prepend sources

* `prepend_sources` - ability to prepend settings via Config without the need to reload settings after they run once.

See section below for more details.

## Working with environment variables
Expand Down
5 changes: 3 additions & 2 deletions lib/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ module Config
env_converter: :downcase,
env_parse_values: true,
fail_on_missing: false,
prepend_sources: [],
# deep_merge options
knockout_prefix: nil,
merge_nil_values: true,
Expand Down Expand Up @@ -57,12 +58,12 @@ def self.load_and_set_settings(*sources)
end

def self.setting_files(config_root, env)
[
(Config.prepend_sources + [
File.join(config_root, 'settings.yml').to_s,
File.join(config_root, 'settings', "#{env}.yml").to_s,
File.join(config_root, 'environments', "#{env}.yml").to_s,
*local_setting_files(config_root, env)
].freeze
]).freeze
end

def self.local_setting_files(config_root, env)
Expand Down
17 changes: 17 additions & 0 deletions spec/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,11 @@
end

context "Custom Configuration" do

before :each do
Config._ran_once=false
end

it "should have the default settings constant as 'Settings'" do
expect(Config.const_name).to eq("Settings")
end
Expand All @@ -206,6 +211,18 @@

expect(Config.const_name).to eq("Settings2")
end

it "should have prepend_sources empty" do
expect(Config.prepend_sources).to eq([])
end

it "should be able to assign prepend_sources" do
Config.setup { |config| config.prepend_sources = ["file.yml"] }

expect(Config.prepend_sources).to eq(["file.yml"])
expect(Config.setting_files("./","test")[0]).to eq("file.yml")
end

end

context "Settings with a type value of 'hash'" do
Expand Down