]> gitweb.fluxo.info Git - leap/leap_cli.git/commitdiff
fixed bugs in ruby 1.9 related to our use of eval.
authorelijah <elijah@riseup.net>
Fri, 2 Nov 2012 04:47:36 +0000 (21:47 -0700)
committerelijah <elijah@riseup.net>
Fri, 2 Nov 2012 04:47:36 +0000 (21:47 -0700)
lib/leap_cli/config/object.rb

index 06a4fef86ed14fee9e83ab825c9e8b0cd47e8f3b..8b14c490e0022b130aa9e557d6cd236b3fb8bfb2 100644 (file)
@@ -43,11 +43,6 @@ module LeapCli
       ## FETCHING VALUES
       ##
 
-      #
-      # like a normal hash [], except:
-      # * lazily eval dynamic values when we encounter them.
-      # * support for nested hashes (e.g. ['a.b'] is the same as ['a']['b'])
-      #
       def [](key)
         get(key)
       end
@@ -67,13 +62,22 @@ module LeapCli
         end
       end
 
+      #
+      # Like a normal Hash#[], except:
+      #
+      # (1) lazily eval dynamic values when we encounter them. (i.e. strings that start with "= ")
+      #
+      # (2) support for nested references in a single string (e.g. ['a.b'] is the same as ['a']['b'])
+      #     the dot path is always absolute, starting at the top-most object.
+      #
       def get!(key)
         key = key.to_s
         if key =~ /\./
+          # for keys with with '.' in them, we start from the root object (@node).
           keys = key.split('.')
-          value = get!(keys.first)
+          value = @node.get!(keys.first)
           if value.is_a? Config::Object
-            value.get!(keys[1..-1])
+            value.get!(keys[1..-1].join('.'))
           else
             value
           end
@@ -136,6 +140,35 @@ module LeapCli
         self
       end
 
+      ##
+      ## MACROS
+      ## these are methods used when eval'ing a value in the .json configuration
+      ##
+
+      #
+      # the list of all the nodes
+      #
+      def nodes
+        global.nodes
+      end
+
+      #
+      # inserts the contents of a file
+      #
+      def file(filename)
+        filepath = Path.find_file(@node.name, filename)
+        if filepath
+          if filepath =~ /\.erb$/
+            ERB.new(File.read(filepath), nil, '%<>').result(binding)
+          else
+            File.read(filepath)
+          end
+        else
+          log0('no such file, "%s"' % filename)
+          ""
+        end
+      end
+
       private
 
       #
@@ -150,7 +183,7 @@ module LeapCli
         else
           if value =~ /^= (.*)$/
             begin
-              value = eval($1, @node.send(:binding))
+              value = @node.instance_eval($1) #, @node.send(:binding))
               self[key] = value
             rescue SystemStackError => exc
               puts "STACK OVERFLOW, BAILING OUT"
@@ -169,35 +202,6 @@ module LeapCli
         end
       end
 
-      ##
-      ## MACROS
-      ## these are methods used when eval'ing a value in the .json configuration
-      ##
-
-      #
-      # the list of all the nodes
-      #
-      def nodes
-        global.nodes
-      end
-
-      #
-      # inserts the contents of a file
-      #
-      def file(filename)
-        filepath = Path.find_file(@node.name, filename)
-        if filepath
-          if filepath =~ /\.erb$/
-            ERB.new(File.read(filepath), nil, '%<>').result(binding)
-          else
-            File.read(filepath)
-          end
-        else
-          log0('no such file, "%s"' % filename)
-          ""
-        end
-      end
-
       #
       # Output json from ruby objects in such a manner that all the hashes and arrays are output in alphanumeric sorted order.
       # This is required so that our generated configs don't throw puppet or git for a tizzy fit.