module Cloudinary::Config

Constants

ENV_URL
SCHEME

Public Instance Methods

load_config_from_env() click to toggle source
# File lib/cloudinary/config.rb, line 8
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 Instance Methods

config_from_parsed_url(parsed_url) click to toggle source
# File lib/cloudinary/config.rb, line 33
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
env_url() click to toggle source
# File lib/cloudinary/config.rb, line 25
def env_url
  ENV_URL
end
expected_scheme() click to toggle source
# File lib/cloudinary/config.rb, line 29
def expected_scheme
  SCHEME
end