cook 2.0.3 → 2.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/cook.rb +1 -1
 - data/lib/rake/config.rb +141 -1
 - metadata +2 -2
 
    
        data/lib/cook.rb
    CHANGED
    
    
    
        data/lib/rake/config.rb
    CHANGED
    
    | 
         @@ -11,6 +11,107 @@ require 'fileutils'; 
     | 
|
| 
       11 
11 
     | 
    
         
             
            require 'cook';
         
     | 
| 
       12 
12 
     | 
    
         
             
            #require 'regexp';
         
     | 
| 
       13 
13 
     | 
    
         | 
| 
      
 14 
     | 
    
         
            +
            class ConfStack
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
              def initialize(object, method, *args)
         
     | 
| 
      
 17 
     | 
    
         
            +
                @confStack = Array.new;
         
     | 
| 
      
 18 
     | 
    
         
            +
                calling(object, method, args);
         
     | 
| 
      
 19 
     | 
    
         
            +
              end
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
              def calling(object, method, where, *args)
         
     | 
| 
      
 22 
     | 
    
         
            +
                @confStack.push([object, method, where, args]) unless
         
     | 
| 
      
 23 
     | 
    
         
            +
                  !@confStack.empty? && 
         
     | 
| 
      
 24 
     | 
    
         
            +
                  @confStack.last[0] == object && 
         
     | 
| 
      
 25 
     | 
    
         
            +
                  @confStack.last[1] == method;
         
     | 
| 
      
 26 
     | 
    
         
            +
              end
         
     | 
| 
      
 27 
     | 
    
         
            +
             
     | 
| 
      
 28 
     | 
    
         
            +
              def reportNoMethodError(errorObject)
         
     | 
| 
      
 29 
     | 
    
         
            +
             
     | 
| 
      
 30 
     | 
    
         
            +
                # Take off the base object (Conf) so that we can use it later to 
         
     | 
| 
      
 31 
     | 
    
         
            +
                # get the missingKey messages
         
     | 
| 
      
 32 
     | 
    
         
            +
                #
         
     | 
| 
      
 33 
     | 
    
         
            +
                confObj = @confStack.shift()[0];
         
     | 
| 
      
 34 
     | 
    
         
            +
             
     | 
| 
      
 35 
     | 
    
         
            +
                # Take of the top of the configure stack so we can treat it as the 
         
     | 
| 
      
 36 
     | 
    
         
            +
                # message which was not found.
         
     | 
| 
      
 37 
     | 
    
         
            +
                #
         
     | 
| 
      
 38 
     | 
    
         
            +
                top     = @confStack.pop();
         
     | 
| 
      
 39 
     | 
    
         
            +
             
     | 
| 
      
 40 
     | 
    
         
            +
                # Compute the full configuration path to report to the user
         
     | 
| 
      
 41 
     | 
    
         
            +
                #
         
     | 
| 
      
 42 
     | 
    
         
            +
                confPath = "Conf";
         
     | 
| 
      
 43 
     | 
    
         
            +
                @confStack.each do | aStackLevel |
         
     | 
| 
      
 44 
     | 
    
         
            +
                  confPath << '.' + aStackLevel[1].to_s;
         
     | 
| 
      
 45 
     | 
    
         
            +
                end
         
     | 
| 
      
 46 
     | 
    
         
            +
                
         
     | 
| 
      
 47 
     | 
    
         
            +
                # Start by dumping the problem together with the FULL backtrace for 
         
     | 
| 
      
 48 
     | 
    
         
            +
                # any experienced user.
         
     | 
| 
      
 49 
     | 
    
         
            +
                #
         
     | 
| 
      
 50 
     | 
    
         
            +
                Rake::Application.mesg ""
         
     | 
| 
      
 51 
     | 
    
         
            +
                Rake::Application.mesg "Could not find the key [#{top[1].to_s}]";
         
     | 
| 
      
 52 
     | 
    
         
            +
                Rake::Application.mesg "in the configuration path [#{confPath}]\n\n";
         
     | 
| 
      
 53 
     | 
    
         
            +
             
     | 
| 
      
 54 
     | 
    
         
            +
                Rake::Application.mesg errorObject.backtrace.join("\n");
         
     | 
| 
      
 55 
     | 
    
         
            +
             
     | 
| 
      
 56 
     | 
    
         
            +
                # Now construct a more user friendly discussion of the problem for 
         
     | 
| 
      
 57 
     | 
    
         
            +
                # novice users.
         
     | 
| 
      
 58 
     | 
    
         
            +
                #
         
     | 
| 
      
 59 
     | 
    
         
            +
                # Start with the problem...
         
     | 
| 
      
 60 
     | 
    
         
            +
                #
         
     | 
| 
      
 61 
     | 
    
         
            +
                Rake::Application.mesg ""
         
     | 
| 
      
 62 
     | 
    
         
            +
                Rake::Application.mesg "=================================================================";
         
     | 
| 
      
 63 
     | 
    
         
            +
                Rake::Application.mesg ""
         
     | 
| 
      
 64 
     | 
    
         
            +
                Rake::Application.mesg "Could not find the key [#{top[1].to_s}]";
         
     | 
| 
      
 65 
     | 
    
         
            +
                Rake::Application.mesg "in the configuration path [#{confPath}]\n\n";
         
     | 
| 
      
 66 
     | 
    
         
            +
             
     | 
| 
      
 67 
     | 
    
         
            +
                # Now collect the parameter lines they will need to specify 
         
     | 
| 
      
 68 
     | 
    
         
            +
                # together with any missingKey messages (in reverse order) that the 
         
     | 
| 
      
 69 
     | 
    
         
            +
                # configuration might have specified.
         
     | 
| 
      
 70 
     | 
    
         
            +
                #
         
     | 
| 
      
 71 
     | 
    
         
            +
                missingKey = confObj.missingKey;
         
     | 
| 
      
 72 
     | 
    
         
            +
                messages = Array.new;
         
     | 
| 
      
 73 
     | 
    
         
            +
                parameterLines = Array.new;
         
     | 
| 
      
 74 
     | 
    
         
            +
                indent = "";
         
     | 
| 
      
 75 
     | 
    
         
            +
                @confStack.each do | aStackLevel |
         
     | 
| 
      
 76 
     | 
    
         
            +
                  parameterLines.push(indent + aStackLevel[1].to_s + ':');
         
     | 
| 
      
 77 
     | 
    
         
            +
                  indent += "  ";
         
     | 
| 
      
 78 
     | 
    
         
            +
                  missingKey = missingKey[aStackLevel[1]] if missingKey.has_key?(aStackLevel[1]);
         
     | 
| 
      
 79 
     | 
    
         
            +
                  messages.unshift(missingKey.delete(:message)) if missingKey.has_key?(:message);
         
     | 
| 
      
 80 
     | 
    
         
            +
                end
         
     | 
| 
      
 81 
     | 
    
         
            +
             
     | 
| 
      
 82 
     | 
    
         
            +
                # Start by printing out any missingKey messages for the missing key 
         
     | 
| 
      
 83 
     | 
    
         
            +
                # itself.
         
     | 
| 
      
 84 
     | 
    
         
            +
                #
         
     | 
| 
      
 85 
     | 
    
         
            +
                missingKey = missingKey[top[1]] if missingKey.has_key?(top[1]);
         
     | 
| 
      
 86 
     | 
    
         
            +
                Rake::Application.mesg missingKey[:message] if missingKey.has_key?(:message);
         
     | 
| 
      
 87 
     | 
    
         
            +
             
     | 
| 
      
 88 
     | 
    
         
            +
                # Now provide a template of the configuration path that seems to be 
         
     | 
| 
      
 89 
     | 
    
         
            +
                # missing together with any specific valueMessage associated with 
         
     | 
| 
      
 90 
     | 
    
         
            +
                # the missing key.
         
     | 
| 
      
 91 
     | 
    
         
            +
                #
         
     | 
| 
      
 92 
     | 
    
         
            +
                Rake::Application.mesg ""
         
     | 
| 
      
 93 
     | 
    
         
            +
                Rake::Application.mesg "Please ensure your configuration contains the following lines"
         
     | 
| 
      
 94 
     | 
    
         
            +
                parameterLines.push(indent + top[1].to_s + ': <<value>>');
         
     | 
| 
      
 95 
     | 
    
         
            +
                Rake::Application.mesg "-----------------------------------------------------------------";
         
     | 
| 
      
 96 
     | 
    
         
            +
                Rake::Application.mesg parameterLines.join("\n");
         
     | 
| 
      
 97 
     | 
    
         
            +
                Rake::Application.mesg "-----------------------------------------------------------------";
         
     | 
| 
      
 98 
     | 
    
         
            +
                Rake::Application.mesg missingKey[:valueMessage] if missingKey.has_key?(:valueMessage);
         
     | 
| 
      
 99 
     | 
    
         
            +
             
     | 
| 
      
 100 
     | 
    
         
            +
                # Now provide any additional configuration messages found most 
         
     | 
| 
      
 101 
     | 
    
         
            +
                # specific first.
         
     | 
| 
      
 102 
     | 
    
         
            +
                #
         
     | 
| 
      
 103 
     | 
    
         
            +
                Rake::Application.mesg ""
         
     | 
| 
      
 104 
     | 
    
         
            +
                Rake::Application.mesg messages.join("\n\n");
         
     | 
| 
      
 105 
     | 
    
         
            +
                Rake::Application.mesg ""
         
     | 
| 
      
 106 
     | 
    
         
            +
             
     | 
| 
      
 107 
     | 
    
         
            +
                # Now exit since there is nothing else we can usefully do to 
         
     | 
| 
      
 108 
     | 
    
         
            +
                # recover
         
     | 
| 
      
 109 
     | 
    
         
            +
                #
         
     | 
| 
      
 110 
     | 
    
         
            +
                exit(-1);
         
     | 
| 
      
 111 
     | 
    
         
            +
              end
         
     | 
| 
      
 112 
     | 
    
         
            +
             
     | 
| 
      
 113 
     | 
    
         
            +
            end
         
     | 
| 
      
 114 
     | 
    
         
            +
             
     | 
| 
       14 
115 
     | 
    
         
             
            class Construct
         
     | 
| 
       15 
116 
     | 
    
         | 
| 
       16 
117 
     | 
    
         
             
              def empty?()
         
     | 
| 
         @@ -29,6 +130,23 @@ class Construct 
     | 
|
| 
       29 
130 
     | 
    
         
             
                @data.each_key(*args, &block)
         
     | 
| 
       30 
131 
     | 
    
         
             
              end
         
     | 
| 
       31 
132 
     | 
    
         | 
| 
      
 133 
     | 
    
         
            +
              alias_method :orig_method_missing, :method_missing;
         
     | 
| 
      
 134 
     | 
    
         
            +
              def method_missing(meth, *args)
         
     | 
| 
      
 135 
     | 
    
         
            +
                Thread.current[:confStack].calling(self, meth, :method_missing, args);
         
     | 
| 
      
 136 
     | 
    
         
            +
                begin
         
     | 
| 
      
 137 
     | 
    
         
            +
                  resultObject = orig_method_missing(meth, *args);
         
     | 
| 
      
 138 
     | 
    
         
            +
                rescue NoMethodError => errorObject
         
     | 
| 
      
 139 
     | 
    
         
            +
                  Thread.current[:confStack].reportNoMethodError(errorObject);
         
     | 
| 
      
 140 
     | 
    
         
            +
                end
         
     | 
| 
      
 141 
     | 
    
         
            +
                resultObject
         
     | 
| 
      
 142 
     | 
    
         
            +
              end
         
     | 
| 
      
 143 
     | 
    
         
            +
             
     | 
| 
      
 144 
     | 
    
         
            +
              alias_method :orig_key_lookup, :[] ;
         
     | 
| 
      
 145 
     | 
    
         
            +
              def [](key)
         
     | 
| 
      
 146 
     | 
    
         
            +
                Thread.current[:confStack].calling(self, key, :key_lookup);
         
     | 
| 
      
 147 
     | 
    
         
            +
                orig_key_lookup(key)
         
     | 
| 
      
 148 
     | 
    
         
            +
              end
         
     | 
| 
      
 149 
     | 
    
         
            +
             
     | 
| 
       32 
150 
     | 
    
         
             
              alias_method :orig_key_value_assignment, :[]= ;
         
     | 
| 
       33 
151 
     | 
    
         
             
              def []=(key, value)
         
     | 
| 
       34 
152 
     | 
    
         
             
                value = Hash.new() if value.nil?;
         
     | 
| 
         @@ -114,10 +232,14 @@ class Conf 
     | 
|
| 
       114 
232 
     | 
    
         
             
              end
         
     | 
| 
       115 
233 
     | 
    
         | 
| 
       116 
234 
     | 
    
         
             
              def self.data
         
     | 
| 
      
 235 
     | 
    
         
            +
                Thread.current[:confStack] = ConfStack.new(self, :Conf);
         
     | 
| 
      
 236 
     | 
    
         
            +
                Thread.current[:confStack].calling(@@data, :data, :data);
         
     | 
| 
       117 
237 
     | 
    
         
             
                return @@data;
         
     | 
| 
       118 
238 
     | 
    
         
             
              end
         
     | 
| 
       119 
239 
     | 
    
         | 
| 
       120 
240 
     | 
    
         
             
              def self.encryptedData
         
     | 
| 
      
 241 
     | 
    
         
            +
                Thread.current[:confStack] = ConfStack.new(self, :Conf);
         
     | 
| 
      
 242 
     | 
    
         
            +
                Thread.current[:confStack].calling(@@encryptedData, :encryptedData, :encryptedData);
         
     | 
| 
       121 
243 
     | 
    
         
             
                return @@encryptedData;
         
     | 
| 
       122 
244 
     | 
    
         
             
              end
         
     | 
| 
       123 
245 
     | 
    
         | 
| 
         @@ -175,6 +297,7 @@ class Conf 
     | 
|
| 
       175 
297 
     | 
    
         
             
              end
         
     | 
| 
       176 
298 
     | 
    
         | 
| 
       177 
299 
     | 
    
         
             
              def self.method_missing(meth, *args)
         
     | 
| 
      
 300 
     | 
    
         
            +
                Thread.current[:confStack] = ConfStack.new(self, :Conf, args);
         
     | 
| 
       178 
301 
     | 
    
         
             
                meth_s = meth.to_s
         
     | 
| 
       179 
302 
     | 
    
         
             
                if @@data.respond_to?(meth) ||
         
     | 
| 
       180 
303 
     | 
    
         
             
                  @@data.data.has_key?(meth) ||
         
     | 
| 
         @@ -182,7 +305,8 @@ class Conf 
     | 
|
| 
       182 
305 
     | 
    
         
             
                  meth_s[-1..-1] == '='then
         
     | 
| 
       183 
306 
     | 
    
         
             
                  @@data.method_missing(meth, *args);
         
     | 
| 
       184 
307 
     | 
    
         
             
                else 
         
     | 
| 
       185 
     | 
    
         
            -
                   
     | 
| 
      
 308 
     | 
    
         
            +
                  self.reportNoMethodError();
         
     | 
| 
      
 309 
     | 
    
         
            +
            #raise ConfigurationError, "No configuation value specified for Conf[#{meth.to_s}]";
         
     | 
| 
       186 
310 
     | 
    
         
             
                end
         
     | 
| 
       187 
311 
     | 
    
         
             
              end
         
     | 
| 
       188 
312 
     | 
    
         | 
| 
         @@ -650,6 +774,22 @@ self.extend Rake::DSL 
     | 
|
| 
       650 
774 
     | 
    
         
             
            #Conf.rsync.cmdOptions = Array.new;
         
     | 
| 
       651 
775 
     | 
    
         
             
            set_command_options(:all);
         
     | 
| 
       652 
776 
     | 
    
         | 
| 
      
 777 
     | 
    
         
            +
            # Ensure we have the basic missingKey error messages
         
     | 
| 
      
 778 
     | 
    
         
            +
            Conf.missingKey = Hash.new;
         
     | 
| 
      
 779 
     | 
    
         
            +
            Conf.missingKey.global = Hash.new;
         
     | 
| 
      
 780 
     | 
    
         
            +
            Conf.missingKey.global.message = <<END_OF_MESSAGE
         
     | 
| 
      
 781 
     | 
    
         
            +
            Global parameters are usually set in the cookbook.conf YAML file 
         
     | 
| 
      
 782 
     | 
    
         
            +
            contained in the .cookbook directory in your home directory.
         
     | 
| 
      
 783 
     | 
    
         
            +
            END_OF_MESSAGE
         
     | 
| 
      
 784 
     | 
    
         
            +
            Conf.missingKey.global.cookbook = Hash.new;
         
     | 
| 
      
 785 
     | 
    
         
            +
            Conf.missingKey.global.cookbook.message = <<END_OF_MESSAGE
         
     | 
| 
      
 786 
     | 
    
         
            +
            The cookbook configuration parameter needs to be set to the location of 
         
     | 
| 
      
 787 
     | 
    
         
            +
            the appropriate cookbook.
         
     | 
| 
      
 788 
     | 
    
         
            +
            END_OF_MESSAGE
         
     | 
| 
      
 789 
     | 
    
         
            +
            Conf.missingKey.global.cookbook.valueMessage = <<END_OF_MESSAGE
         
     | 
| 
      
 790 
     | 
    
         
            +
            where <<value>> is the full path to the approprate cookbook directory.
         
     | 
| 
      
 791 
     | 
    
         
            +
            END_OF_MESSAGE
         
     | 
| 
      
 792 
     | 
    
         
            +
             
     | 
| 
       653 
793 
     | 
    
         
             
            # Ensure the gpg hash exists (but may be empty)
         
     | 
| 
       654 
794 
     | 
    
         
             
            Conf.gpg = Hash.new;
         
     | 
| 
       655 
795 
     | 
    
         | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: cook
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 2.0. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 2.0.4
         
     | 
| 
       5 
5 
     | 
    
         
             
              prerelease: 
         
     | 
| 
       6 
6 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       7 
7 
     | 
    
         
             
            authors:
         
     | 
| 
         @@ -9,7 +9,7 @@ authors: 
     | 
|
| 
       9 
9 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       10 
10 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       11 
11 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       12 
     | 
    
         
            -
            date: 2014-02- 
     | 
| 
      
 12 
     | 
    
         
            +
            date: 2014-02-17 00:00:00.000000000 Z
         
     | 
| 
       13 
13 
     | 
    
         
             
            dependencies:
         
     | 
| 
       14 
14 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       15 
15 
     | 
    
         
             
              name: rake
         
     |