Class: ConfStack
- Inherits:
-
Object
- Object
- ConfStack
- Defined in:
- lib/rake/config.rb
Overview
require ‘regexp’;
Instance Method Summary collapse
- #calling(object, method, where, *args) ⇒ Object
-
#initialize(object, method, *args) ⇒ ConfStack
constructor
A new instance of ConfStack.
- #reportNoMethodError(errorObject) ⇒ Object
Constructor Details
#initialize(object, method, *args) ⇒ ConfStack
Returns a new instance of ConfStack.
16 17 18 19 |
# File 'lib/rake/config.rb', line 16 def initialize(object, method, *args) @confStack = Array.new; calling(object, method, args); end |
Instance Method Details
#calling(object, method, where, *args) ⇒ Object
21 22 23 24 25 26 |
# 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) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# 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"); # 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; = 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]); .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 .join("\n\n"); Rake::Application.mesg "" # Now exit since there is nothing else we can usefully do to # recover # exit(-1); end |