class Alchemy::Config

Public Class Methods

deprecated_configs() click to toggle source

A list of deprecated configuration values a value of nil means there is no new default any not nil value is the new default

# File lib/alchemy/config.rb, line 34
def deprecated_configs
  {}
end
get(name) click to toggle source

Returns the configuration for given parameter name.

@param name [String]

# File lib/alchemy/config.rb, line 10
def get(name)
  check_deprecation(name)
  key = check_replacement(name)
  show[key.to_s]
end
Also aliased as: parameter
parameter(name)
Alias for: get
replaced_config_keys() click to toggle source

A list of replaced configuration keys

# File lib/alchemy/config.rb, line 39
def replaced_config_keys
  {
    output_image_quality: :output_image_jpg_quality
  }
end
show() click to toggle source

Returns a merged configuration of the following files

Alchemys default config: gems/../alchemy_cms/config/alchemy/config.yml Your apps default config: your_app/config/alchemy/config.yml Environment specific config: your_app/config/alchemy/development.config.yml

An environment specific config overwrites the settings of your apps default config, while your apps default config has precedence over Alchemys default config.

# File lib/alchemy/config.rb, line 27
def show
  @config ||= merge_configs!(alchemy_config, main_app_config, env_specific_config)
end

Private Class Methods

alchemy_config() click to toggle source

Alchemy default configuration

# File lib/alchemy/config.rb, line 48
def alchemy_config
  read_file Engine.root.join("config/alchemy/config.yml")
end
check_deprecation(name) click to toggle source
# File lib/alchemy/config.rb, line 85
def check_deprecation(name)
  if deprecated_configs.key?(name.to_sym)
    config = deprecated_configs[name.to_sym]
    if config.nil?
      Alchemy::Deprecation.warn("#{name} configuration is deprecated and will be removed from Alchemy #{Alchemy::Deprecation.deprecation_horizon}")
    else
      value = show[name.to_s]
      if value != config
        Alchemy::Deprecation.warn("Setting #{name} configuration to #{value} is deprecated and will be always #{config} in Alchemy #{Alchemy::Deprecation.deprecation_horizon}")
      end
    end
  end
end
check_replacement(name) click to toggle source
# File lib/alchemy/config.rb, line 99
def check_replacement(name)
  if replaced_config_keys.key?(name.to_sym)
    old_key = replaced_config_keys[name.to_sym]
    if show[old_key.to_s]
      Alchemy::Deprecation.warn("Using #{old_key} configuration is deprecated and will be removed in Alchemy #{Alchemy::Deprecation.deprecation_horizon}. Please use #{name} instead.")
      old_key
    else
      name
    end
  else
    name
  end
end
env_specific_config() click to toggle source

Rails Environment specific configuration

# File lib/alchemy/config.rb, line 58
def env_specific_config
  read_file Rails.root.join("config/alchemy/#{Rails.env}.config.yml")
end
main_app_config() click to toggle source

Application specific configuration

# File lib/alchemy/config.rb, line 53
def main_app_config
  read_file Rails.root.join("config/alchemy/config.yml")
end
merge_configs!(*config_files) click to toggle source

Merges all given configs together

# File lib/alchemy/config.rb, line 77
def merge_configs!(*config_files)
  raise LoadError, "No Alchemy config file found!" if config_files.map(&:blank?).all?

  config = {}
  config_files.each { |h| config.merge!(h.stringify_keys!) }
  config
end
read_file(file) click to toggle source

Tries to load yaml file from given path. If it does not exist, or its empty, it returns an empty Hash.

# File lib/alchemy/config.rb, line 65
def read_file(file)
  YAML.safe_load(
    ERB.new(File.read(file)).result,
    permitted_classes: YAML_PERMITTED_CLASSES,
    aliases: true
  ) || {}
rescue Errno::ENOENT
  {}
end