require_relative "global" require "active_support/core_ext/string" module Hitcher module Dsl def logger Hitcher::Global.instance.glog end # logger def start(cont) cont.each do |c| c = c.strip if not c =~ /^#/ and not c.empty? # ignoring comment eeval(c) end end @inst #logger.debug "Start ends" #if not @inst.nil? # @inst.gen #end end def container(type) logger.debug "Container #{type}" case type when :docker contDir = File.join(File.dirname(__FILE__),"providers",type.to_s) logger.debug "Provider loaded from '#{contDir}'" if File.exist?(contDir) require_relative File.join(contDir,"dsl") # blend into this module #self.class.send(:include, eval("Hitcher::#{type.to_s.classify}::Dsl")) clsName = type.to_s.classify @inst = eval("Hitcher::#{clsName}::#{clsName}Dsl.new") else raise Hitcher::Error, "Provider '#{type}' not found" end else raise Hitcher::Error, "Unknown container type '#{type}'" end end def method_missing(mtd,*args,&block) @inst.send(mtd,*args,&block) end # missing_method private def eeval(ln) if @inst.nil? ll = ln.split(" ") if ll[0] == "version" @version = ll[1].strip elsif ll[0] == "container" eval(ln) else raise Error, "Container needs to be defined before proceeding." end elsif ln =~ /end/ raise Error, "No block start keyword do_plain or do defined but end keyword is found" if @blc.nil? @blc << ln if @mode == :cblock @inst.handle_block(@kw, @blc) else self.instance_eval(@blc.join("\n")) end @mode = :linear @kw = nil @blc.clear @blc = nil elsif ln =~ /do_plain/ or @mode == :cblock if @mode != :cblock kw = ln.split(" ")[0] if @inst.block_kw?(kw) @blc = [] @mode = :cblock @kw = kw else raise Error, "Unknown block method #{kw}" end end @blc << ln elsif ln =~ /do/ or @mode == :block if @mode != :block @blc = [] @kw = ln.split(" ")[0] @mode = :block end @blc << ln else @inst.instance_eval(ln) end end end end