Class: RBatch::Variables
- Inherits:
-
Object
- Object
- RBatch::Variables
- Defined in:
- lib/rbatch/variables.rb
Instance Attribute Summary (collapse)
-
- (Object) merged_opt
readonly
Returns the value of attribute merged_opt.
-
- (Object) run_conf
readonly
Returns the value of attribute run_conf.
-
- (Object) vars
readonly
Returns the value of attribute vars.
Instance Method Summary (collapse)
-
- (Object) [](key)
end def.
-
- (Variables) initialize(run_conf = nil)
constructor
A new instance of Variables.
- - (Object) merge(merged_opt)
- - (Object) merge!(merged_opt)
- - (Object) raw_value(key)
Constructor Details
- (Variables) initialize(run_conf = nil)
Returns a new instance of Variables
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/rbatch/variables.rb', line 8 def initialize(run_conf=nil) @merged_opt = {} @vars = { :program_name => $PROGRAM_NAME , :program_path => File.($PROGRAM_NAME) , :program_base => File.basename($PROGRAM_NAME), :date => Time.now.strftime("%Y%m%d"), :time => Time.now.strftime("%H%M%S"), } @vars[:program_noext] = Pathname(@vars[:program_base]).sub_ext("").to_s 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.(ENV["RB_HOME"]) else @vars[:home_dir] = File.(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],@vars[:program_noext] + ".yaml") end |
Instance Attribute Details
- (Object) merged_opt (readonly)
Returns the value of attribute merged_opt
7 8 9 |
# File 'lib/rbatch/variables.rb', line 7 def merged_opt @merged_opt end |
- (Object) run_conf (readonly)
Returns the value of attribute run_conf
7 8 9 |
# File 'lib/rbatch/variables.rb', line 7 def run_conf @run_conf end |
- (Object) vars (readonly)
Returns the value of attribute vars
7 8 9 |
# File 'lib/rbatch/variables.rb', line 7 def vars @vars end |
Instance Method Details
- (Object) [](key)
end def
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/rbatch/variables.rb', line 40 def[](key) if @vars.has_key?(key) if @vars[key].class == String @vars[key] .gsub("<home>", @vars[:home_dir]) .gsub("<date>", @vars[:date]) .gsub("<time>", @vars[:time]) .gsub("<prog>", @vars[:program_noext]) .gsub("<host>", @vars[:host_name]) else @vars[key] end else raise RBatch::VariablesException, "no such key exist :" + key.to_s end end |
- (Object) merge(merged_opt)
71 72 73 74 75 |
# File 'lib/rbatch/variables.rb', line 71 def merge(merged_opt) @merged_opt = merged_opt @vars.merge!(merged_opt) return self end |
- (Object) merge!(merged_opt)
65 66 67 68 69 |
# File 'lib/rbatch/variables.rb', line 65 def merge!(merged_opt) @merged_opt = merged_opt @vars.merge!(merged_opt) return nil end |
- (Object) raw_value(key)
57 58 59 60 61 62 63 |
# File 'lib/rbatch/variables.rb', line 57 def raw_value(key) if @vars.has_key?(key) @vars[key] else raise RBatch::VariablesException, "no such key exist :" + key.to_s end end |