Class: RBatch::Config

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

Instance Method Summary (collapse)

Constructor Details

- (Config) initialize(path)

Returns a new instance of Config

Parameters:

  • path (String)

    Config file path



14
15
16
17
18
19
20
21
# File 'lib/rbatch/config.rb', line 14

def initialize(path)
  @path = path
  begin
    @hash = ConfigElement.new(YAML::load_file(@path))
  rescue Errno::ENOENT => e
    @hash = nil
  end
end

Instance Method Details

- (Object) [](key)

Config value

Parameters:

  • key (Object)

    Config key.

Raises:



26
27
28
29
30
31
32
# File 'lib/rbatch/config.rb', line 26

def[](key)
  if @hash.nil?
    raise RBatch::ConfigException, "Config file \"#{@path}\" does not exist"
  else
    @hash[key]
  end
end

- (Boolean) exist?

Config file exists or not

Returns:

  • (Boolean)


40
# File 'lib/rbatch/config.rb', line 40

def exist? ; ! @hash.nil? ; end

- (String) path

Config file path

Returns:

  • (String)


36
# File 'lib/rbatch/config.rb', line 36

def path ; @path ; end

- (Hash) to_h

Returns:

  • (Hash)


43
44
45
46
47
48
49
# File 'lib/rbatch/config.rb', line 43

def to_h
  if @hash.nil?
    raise RBatch::ConfigException, "Config file \"#{@path}\" does not exist"
  else
    @hash
  end
end

- (String) to_s

Returns:

  • (String)


52
53
54
55
56
57
58
# File 'lib/rbatch/config.rb', line 52

def to_s
  if @hash.nil?
    raise RBatch::ConfigException, "Config file \"#{@path}\" does not exist"
  else
    @hash.to_s
  end
end