Class: RBatch::RunConf

Inherits:
Object
  • Object
show all
Defined in:
lib/rbatch/run_conf.rb

Constant Summary

@@def_opt =
{
  :conf_dir      => "<home>/conf",
  :common_conf_name => "common.yaml",
  :lib_dir       => "<home>/lib",
  :auto_lib_load => true,
  :forbid_double_run => false,
  :cmd_raise     => false,
  :cmd_timeout   => 0,
  :log_dir       => "<home>/log",
  :log_name      => "<date>_<time>_<prog>.log",
  :log_append    => true,
  :log_level     => "info",
  :log_stdout    => false,
  :log_delete_old_log => false,
  :log_delete_old_log_date => 7,
  :log_send_mail => false,
  :log_bufferd => false,
  :log_output_exit_status => true,
  :log_mail_to   => nil,
  :log_mail_from => "rbatch.localhost",
  :log_mail_server_host => "localhost",
  :log_mail_server_port => 25,
  :rbatch_journal_level => 1,
  :mix_rbatch_journal_to_logs => true
}

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (RunConf) initialize(path = nil)

Returns a new instance of RunConf



33
34
35
36
37
38
39
40
41
# File 'lib/rbatch/run_conf.rb', line 33

def initialize(path=nil)
  if path.nil?
    @opt = @@def_opt.clone
  else
    @path = path
    @opt = @@def_opt.clone
    load
  end
end

Instance Attribute Details

- (Object) path (readonly)

Returns the value of attribute path



6
7
8
# File 'lib/rbatch/run_conf.rb', line 6

def path
  @path
end

Instance Method Details

- (Object) [](key)



87
88
89
90
91
92
# File 'lib/rbatch/run_conf.rb', line 87

def[](key)
  if @opt[key].nil?
    raise RBatch::RunConfException, "Value of key=\"#{key}\" is nil"
  end
  @opt[key]
end

- (Object) []=(key, value)



94
95
96
97
98
99
# File 'lib/rbatch/run_conf.rb', line 94

def[]=(key,value)
  if ! @opt.has_key?(key)
    raise RBatch::RunConfException, "Key=\"#{key}\" does not exist"
  end
  @opt[key]=value
end

- (Boolean) has_key?(key)

Returns:

  • (Boolean)


61
62
63
# File 'lib/rbatch/run_conf.rb', line 61

def has_key?(key)
  @opt.has_key?(key)
end

- (Object) load



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/rbatch/run_conf.rb', line 43

def load()
  begin
    @yaml = YAML::load_file(@path)
  rescue
    # when run_conf does not exist, do nothing.
    @yaml = false
  end
  if @yaml
    @yaml.each_key do |key|
      if @@def_opt.has_key?(key.to_sym)
        @opt[key.to_sym]=@yaml[key]
      else
        raise RBatch::RunConfException, "\"#{key}\" is not available option"
      end
    end
  end
end

- (Object) merge(opt)



75
76
77
78
79
80
81
82
83
84
85
# File 'lib/rbatch/run_conf.rb', line 75

def merge(opt)
  tmp = @opt.clone
  opt.each_key do |key|
    if tmp.has_key?(key)
      tmp[key] = opt[key]
    else
      raise RBatch::RunConfException, "\"#{key}\" is not available option"
    end
  end
  return tmp
end

- (Object) merge!(opt)



65
66
67
68
69
70
71
72
73
# File 'lib/rbatch/run_conf.rb', line 65

def merge!(opt)
  opt.each_key do |key|
    if @opt.has_key?(key)
      @opt[key] = opt[key]
    else
      raise RBatch::RunConfException, "\"#{key}\" is not available option"
    end
  end
end