Sha256: 88c4aad304ac11532efbf76c730390d5d15a2fa3d7193509fb6334cf5c789d75

Contents?: true

Size: 1.19 KB

Versions: 16

Compression:

Stored size: 1.19 KB

Contents

module Cloudinary
  module Config
    include BaseConfig

    ENV_URL = "CLOUDINARY_URL"
    SCHEME = "cloudinary"

    def load_config_from_env
      if ENV["CLOUDINARY_CLOUD_NAME"]
        config_keys = ENV.keys.select! { |key| key.start_with? "CLOUDINARY_" }
        config_keys -= ["CLOUDINARY_URL"] # ignore it when explicit options are passed
        config_keys.each do |full_key|
          conf_key = full_key["CLOUDINARY_".length..-1].downcase # convert "CLOUDINARY_CONFIG_NAME" to "config_name"
          conf_val = ENV[full_key]
          conf_val = conf_val == 'true' if %w[true false].include?(conf_val) # cast relevant boolean values
          update(conf_key => conf_val)
        end
      elsif ENV[ENV_URL]
        load_from_url(ENV[ENV_URL])
      end
    end

    private

    def env_url
      ENV_URL
    end

    def expected_scheme
      SCHEME
    end

    def config_from_parsed_url(parsed_url)
      {
        "cloud_name"          => parsed_url.host,
        "api_key"             => parsed_url.user,
        "api_secret"          => parsed_url.password,
        "private_cdn"         => !parsed_url.path.blank?,
        "secure_distribution" => parsed_url.path[1..-1]
      }
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
cloudinary-2.2.0 lib/cloudinary/config.rb
cloudinary-2.1.2 lib/cloudinary/config.rb
cloudinary-2.0.2 lib/cloudinary/config.rb
cloudinary-2.0.1 lib/cloudinary/config.rb
cloudinary-2.0.0 lib/cloudinary/config.rb
cloudinary-1.29.0 lib/cloudinary/config.rb
cloudinary-1.28.0 lib/cloudinary/config.rb
cloudinary-1.27.0 lib/cloudinary/config.rb
cloudinary-1.26.0 lib/cloudinary/config.rb
cloudinary-1.25.0 lib/cloudinary/config.rb
cloudinary-1.24.0 lib/cloudinary/config.rb
cloudinary-1.23.0 lib/cloudinary/config.rb
cloudinary-1.22.0 lib/cloudinary/config.rb
cloudinary-1.21.0 lib/cloudinary/config.rb
cloudinary-1.20.0 lib/cloudinary/config.rb
cloudinary-1.19.0 lib/cloudinary/config.rb