module Cloudinary

Copyright Cloudinary

Constants

FORMAT_ALIASES
SHARED_CDN
USER_AGENT
VERSION

Public Class Methods

USER_AGENT() click to toggle source
# File lib/cloudinary.rb, line 45
def self.USER_AGENT
  if @@user_platform.empty?
    USER_AGENT
  else
    "#{@@user_platform} #{USER_AGENT}"
  end
end
account_config(new_config=nil) { |account_config| ... } click to toggle source

Cloudinary account config

@param [Hash] new_config If new_config is passed, Account Config will be updated with it @yieldparam [OpenStruct] Account config can be updated in the block

@return [OpenStruct]

# File lib/cloudinary.rb, line 82
def self.account_config(new_config=nil)
  @@account_config ||= make_new_config(AccountConfig)

  @@account_config.update(new_config) if new_config
  yield @@account_config if block_given?

  @@account_config
end
app_root() click to toggle source
# File lib/cloudinary.rb, line 99
def self.app_root
  if defined? Rails::root
    # Rails 2.2 return String for Rails.root
    Rails.root.is_a?(Pathname) ? Rails.root : Pathname.new(Rails.root)
  else
    Pathname.new(".")
  end
end
config(new_config=nil) { |config| ... } click to toggle source

Cloudinary config

@param [Hash] new_config If new_config is passed, Config will be updated with it @yieldparam [OpenStruct] Config can be updated in the block

@return [OpenStruct]

# File lib/cloudinary.rb, line 67
def self.config(new_config=nil)
  @@config ||= make_new_config(Config)

  @@config.update(new_config) if new_config
  yield @@config if block_given?

  @@config
end
config_from_account_url(url) click to toggle source
# File lib/cloudinary.rb, line 95
def self.config_from_account_url(url)
  account_config.load_from_url(url)
end
config_from_url(url) click to toggle source
# File lib/cloudinary.rb, line 91
def self.config_from_url(url)
  config.load_from_url(url)
end
user_platform() click to toggle source
# File lib/cloudinary.rb, line 41
def self.user_platform
  @@user_platform
end
user_platform=(value) click to toggle source

Add platform information to the USER_AGENT header This is intended for platform information and not individual applications!

# File lib/cloudinary.rb, line 37
def self.user_platform=(value)
  @@user_platform= value
end

Private Class Methods

config_dir() click to toggle source
# File lib/cloudinary.rb, line 116
def self.config_dir
  return Pathname.new(ENV["CLOUDINARY_CONFIG_DIR"]) if ENV["CLOUDINARY_CONFIG_DIR"]
  self.app_root.join("config")
end
config_env() click to toggle source
# File lib/cloudinary.rb, line 110
def self.config_env
  return ENV["CLOUDINARY_ENV"] if ENV["CLOUDINARY_ENV"]
  return Rails.env if defined? Rails::env
  nil
end
import_settings_from_file() click to toggle source

Import settings from yaml file

@return [OpenStruct]

# File lib/cloudinary.rb, line 142
def self.import_settings_from_file
  yaml_env_config = begin
    yaml_source = ERB.new(IO.read(config_dir.join("cloudinary.yml"))).result
    yaml_config = if YAML.respond_to?(:safe_load)
                    YAML.safe_load(yaml_source, aliases: true)
                  else
                    YAML.load(yaml_source)
                  end
    yaml_config[config_env]
  rescue StandardError
    {}
  end
  OpenStruct.new(yaml_env_config)
end
make_new_config(config_module) click to toggle source

Builds config from yaml file, extends it with specific module and loads configuration from environment variable

@param [Module] config_module Config is extended with this module after being built

@return [OpenStruct]

# File lib/cloudinary.rb, line 130
def self.make_new_config(config_module)
  import_settings_from_file.tap do |config|
    config.extend(config_module)
    config.load_config_from_env
  end
end
set_config(new_config) click to toggle source
# File lib/cloudinary.rb, line 121
def self.set_config(new_config)
  new_config.each{|k,v| @@config.send(:"#{k}=", v) if !v.nil?}
end