require 'rbatch/run_conf' module RBatch class Variables attr :vars,:run_conf,:merged_opt def initialize(run_conf=nil) @merged_opt = {} @vars = { :program_name => $PROGRAM_NAME , :program_path => File.expand_path($PROGRAM_NAME) , :program_base => File.basename($PROGRAM_NAME), :date => Time.now.strftime("%Y%m%d"), :time => Time.now.strftime("%H%M%S"), } if ENV["RB_VERBOSE"] @vars[:journal_verbose] = ENV["RB_VERBOSE"].to_i else @vars[:journal_verbose] = 1 end case RUBY_PLATFORM when /mswin|mingw/ @vars[:host_name] = ENV["COMPUTERNAME"] ? ENV["COMPUTERNAME"] : "unknownhost" when /cygwin|linux/ @vars[:host_name] = ENV["HOSTNAME"] ? ENV["HOSTNAME"] : "unknownhost" else @vars[:host_name] = "unknownhost" end if ENV["RB_HOME"] @vars[:home_dir] = File.expand_path(ENV["RB_HOME"]) else @vars[:home_dir] = File.expand_path(File.join(File.dirname(@vars[:program_name]), "..")) end @vars[:run_conf_path] = File.join(@vars[:home_dir],".rbatchrc") @run_conf = RunConf.new(@vars[:run_conf_path]) # load run_conf @vars.merge!(@run_conf.opt) @vars[:common_config_path] = File.join(@vars[:conf_dir],@vars[:common_conf_name]) @vars[:config_path] = File.join(@vars[:conf_dir],Pathname(File.basename(@vars[:program_name])).sub_ext(".yaml").to_s) end #end def def[](key) if @vars.has_key?(key) if @vars[key].class == String @vars[key] .gsub("", @vars[:home_dir]) .gsub("", @vars[:date]) .gsub("