Commits

Kaspar Schiess committed 902f557

Adds support for helper libraries

VM definitions can now use helper libraries to do their bidding. This
allows the Rubyist to DRY up large installations with a few helper
functions.

  • Participants
  • Parent commits 23e1b91

Comments (0)

Files changed (6)

File Gemfile.lock

 PATH
   remote: .
   specs:
-    qemu-toolkit (0.3.1)
+    qemu-toolkit (0.3.2)
       clamp (~> 0.5)
 
 GEM
 = 0.4
   
   ! Fixes missing requires for fileutils
-  ! Fixes for documentation on the VNC port. 
-  + 'keyboard_layout' option for defining the layout for VNC connections.
+  ! Fixes for documentation on the VNC port
+  + 'keyboard_layout' option for defining the layout for VNC connections
+  + Support for a 'lib'-directory in /etc for helper functions
+  + Support for using Ruby libraries in VM definitions
   
 = 0.3
   

File lib/qemu-toolkit/dsl.rb

           binding, 
           path)
       end
+      def require file
+        Kernel.require file
+      end
       def add_toplevel_target target, producer
         define_singleton_method(target) { |*args, &block| 
           object = producer.call(*args) 

File lib/qemu-toolkit/vm.rb

       #
       def all(backend=nil)
         Enumerator.new do |yielder|
+          libdir = Config.etc('lib')
+          if File.directory? libdir
+            $:.unshift libdir
+          end
+          
           Dir[Config.etc('*.rb')].each do |vm_file|
             # Load all virtual machines from the given file
             dsl = DSL::File.new

File spec/fixture/etc/helper.rb

+require 'helper'
+
+virtual_machine "helper" do
+  cpus Helper.the_answer
+end

File spec/fixture/etc/lib/helper.rb

+module Helper
+  def the_answer
+    42
+  end
+  module_function :the_answer
+end