module PowerStencil::Project::Config

Constants

PLUGIN_CONFIG_PRIORITY_MIN
PROJECT_CONFIG_PRIORITY
USER_CONFIG_PRIORITY

Attributes

plugin_priority_count[R]

Public Instance Methods

add_plugin_config(plugin) click to toggle source
# File lib/power_stencil/project/config.rb, line 24
def add_plugin_config(plugin)
  plugin_name = plugin.name
  yaml_file = plugin.plugin_config_specific_file
  priority = if priority.nil?
               PLUGIN_CONFIG_PRIORITY_MIN
             else
               plugin_priority_count + 1
             end
  raise PowerStencil::Error, 'Too many plugins !!' if priority >= PROJECT_CONFIG_PRIORITY
  raise PowerStencil::Error, "Invalid config for plugin '#{plugin_name}'" unless add_optional_config_layer yaml_file, "'#{plugin_name}' plugin specific config", priority
  @plugin_priority_count ||= 0
  @plugin_priority_count += 1
end
load_project_specific_config() click to toggle source
# File lib/power_stencil/project/config.rb, line 15
def load_project_specific_config
  # Optional config files should have less priority than the command line layer
  add_optional_config_layer project_versioned_config_file, 'versioned project config file', PROJECT_CONFIG_PRIORITY
  add_optional_config_layer project_personal_config_file, 'personal project config file', USER_CONFIG_PRIORITY
  Climatic.send :setup_logger
  logger.debug 'Project config files loaded'
end

Private Instance Methods

add_optional_config_layer(yaml_file, layer_name, layer_priority) click to toggle source
# File lib/power_stencil/project/config.rb, line 40
def add_optional_config_layer(yaml_file, layer_name, layer_priority)
  if File.readable? yaml_file
    logger.debug "Loading #{layer_name}: '#{yaml_file}'..."
    begin
      new_config_layer = SuperStack::Layer.new.load yaml_file
      new_config_layer.name = layer_name
      new_config_layer.priority = layer_priority
      config << new_config_layer
      new_config_layer
    rescue => e
      logger.debug PowerStencil::Error.report_error(e)
      logger.error "The #{layer_name} '#{yaml_file}' is invalid and has been ignored !"
      false
    end
  else
    logger.debug "No #{layer_name} found."
    false
  end
end