cloudinary / cloudinary_gem

Cloudinary GEM for Ruby on Rails integration
https://cloudinary.com
420 stars 285 forks source link

Configuration: use YAML.safe_load and allowing aliases (for Ruby 3.1) #484

Closed jlestavel closed 2 years ago

jlestavel commented 2 years ago

Brief Summary of Changes

The goal of this PR is to have YAML aliases supported for the config file in Ruby 3.1

By default, Ruby 3.1 will use safe_load so we have to explicitly allow aliases

cf

Psych 4.0 changes Psych.load as safe_load by the default. You may need to use Psych 3.3.2 for migrating to this behavior. [Bug #17866]

in https://www.ruby-lang.org/en/news/2021/12/25/ruby-3-1-0-released/

For example in our project, the config/cloudinary.yml file looks like

---
default: &default
  api_key: '<%= ENV['CLOUDINARY_API_KEY'] %>'
  api_secret: '<%= ENV['CLOUDINARY_API_SECRET'] %>'
staging: &staging
  <<: *default
  cloud_name: our_test_cloud
development: *staging
test: *staging
production:
  <<: *default
  cloud_name: our_prod_cloud

and it's not supported by the current version of the gem

I submitted a similar for another gem, database_consistency, that was accepted if you want to have a look: https://github.com/djezzzl/database_consistency/pull/113

What does this PR address?

Are tests included?

Checklist:

julianrubisch commented 2 years ago

I can confirm that this fixes an issue with Ruby 3.1

I was seeing config errors in my app a la ActionView::Template::Error: Must supply cloud_name in tag or in configuration

It turns out that I was also using YAML aliases as suggested in this PR, and checking it out fixed it for me.

const-cloudinary commented 2 years ago

@jlestavel , thank you for contribution!