class ConfStack

require ‘regexp’;

Public Class Methods

new(object, method, *args) click to toggle source
# File lib/rake/config.rb, line 16
def initialize(object, method, *args)
  @confStack = Array.new;
  calling(object, method, args);
end

Public Instance Methods

calling(object, method, where, *args) click to toggle source
# File lib/rake/config.rb, line 21
def calling(object, method, where, *args)
  @confStack.push([object, method, where, args]) unless
    !@confStack.empty? && 
    @confStack.last[0] == object && 
    @confStack.last[1] == method;
end
reportNoMethodError(errorObject) click to toggle source
# File lib/rake/config.rb, line 28
def reportNoMethodError(errorObject)

  # Take off the base object (Conf) so that we can use it later to
  # get the missingKey messages
  #
  confObj = @confStack.shift()[0];

  # Take of the top of the configure stack so we can treat it as the
  # message which was not found.
  #
  top     = @confStack.pop();

  # Compute the full configuration path to report to the user
  #
  confPath = "Conf";
  @confStack.each do | aStackLevel |
    confPath << '.' + aStackLevel[1].to_s;
  end
  
  # Start by dumping the problem together with the FULL backtrace for
  # any experienced user.
  #
  Rake::Application.mesg ""
  Rake::Application.mesg "Could not find the key [#{top[1].to_s}]";
  Rake::Application.mesg "in the configuration path [#{confPath}]\n\n";

  Rake::Application.mesg errorObject.backtrace.join("\n") unless errorObject.backtrace.nil?;

  # Now construct a more user friendly discussion of the problem for
  # novice users.
  #
  # Start with the problem...
  #
  Rake::Application.mesg ""
  Rake::Application.mesg "=================================================================";
  Rake::Application.mesg ""
  Rake::Application.mesg "Could not find the key [#{top[1].to_s}]";
  Rake::Application.mesg "in the configuration path [#{confPath}]\n\n";

  # Now collect the parameter lines they will need to specify
  # together with any missingKey messages (in reverse order) that the
  # configuration might have specified.
  #
  missingKey = confObj.missingKey;
  messages = Array.new;
  parameterLines = Array.new;
  indent = "";
  @confStack.each do | aStackLevel |
    parameterLines.push(indent + aStackLevel[1].to_s + ':');
    indent += "  ";
    missingKey = missingKey[aStackLevel[1]] if missingKey.has_key?(aStackLevel[1]);
    messages.unshift(missingKey.delete(:message)) if missingKey.has_key?(:message);
  end

  # Start by printing out any missingKey messages for the missing key
  # itself.
  #
  missingKey = missingKey[top[1]] if missingKey.has_key?(top[1]);
  Rake::Application.mesg missingKey[:message] if missingKey.has_key?(:message);

  # Now provide a template of the configuration path that seems to be
  # missing together with any specific valueMessage associated with
  # the missing key.
  #
  Rake::Application.mesg ""
  Rake::Application.mesg "Please ensure your configuration contains the following lines"
  parameterLines.push(indent + top[1].to_s + ': <<value>>');
  Rake::Application.mesg "-----------------------------------------------------------------";
  Rake::Application.mesg parameterLines.join("\n");
  Rake::Application.mesg "-----------------------------------------------------------------";
  Rake::Application.mesg missingKey[:valueMessage] if missingKey.has_key?(:valueMessage);

  # Now provide any additional configuration messages found most
  # specific first.
  #
  Rake::Application.mesg ""
  Rake::Application.mesg messages.join("\n\n");
  Rake::Application.mesg ""

  # Now exit since there is nothing else we can usefully do to
  # recover
  #
  exit(-1);
end