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

Support Psych 4.X+ to correctly handle YAML aliases, fixes #15 #16

Merged
merged 1 commit into from
Dec 20, 2022
Merged
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
15 changes: 15 additions & 0 deletions Appraisals
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,18 @@ end
appraise "rails-7" do
gem "rails", "~> 7.0"
end

appraise "psych-3.3" do
gem "rails", "~> 7.0"
gem "psych", "~> 3.3"
end

appraise "psych-4.0" do
gem "rails", "~> 7.0"
gem "psych", "~> 4.0"
end

appraise "psych-5.0" do
gem "rails", "~> 7.0"
gem "psych", "~> 5.0"
end
12 changes: 11 additions & 1 deletion lib/figjam/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,17 @@ def raw_configuration
end

def parse(path)
File.exist?(path) && YAML.load(ERB.new(File.read(path)).result) || {}
File.exist?(path) && load_yaml(ERB.new(File.read(path)).result) || {}
end

def load_yaml(source)
# https://bugs.ruby-lang.org/issues/17866
# https://github.com/rails/rails/commit/179d0a1f474ada02e0030ac3bd062fc653765dbe
begin
YAML.load(source, aliases: true) || {}
rescue ArgumentError
YAML.load(source) || {}
end
end

def global_configuration
Expand Down
6 changes: 6 additions & 0 deletions spec/figjam_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@
end
end

describe "#configuration" do
it "includes configuration using YAML aliases" do
expect(ENV['WHEEL_COUNT']).to eq('4')
end
end

describe "railtie configuration" do
it "loads railtie after the adapter is set to Figaro::Rails::Application" do
expect(ENV['ENGINE_VALUE']).to eq('diesel')
Expand Down
6 changes: 6 additions & 0 deletions spec/internal/config/application.yml
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
ENGINE_VALUE: diesel

test_default: &test_default
WHEEL_COUNT: "4"

test:
<<: *test_default