Class: Idcf::Cli::Lib::Util::YmlConf

Inherits:
Object
  • Object
show all
Defined in:
lib/idcf/cli/lib/util/yml_conf.rb

Overview

yml conf

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*path) ⇒ YmlConf

initialize

Parameters:

  • path (String)

    yml file path



23
24
25
# File 'lib/idcf/cli/lib/util/yml_conf.rb', line 23

def initialize(*path)
  @load_data = YAML.load_file(path[0])
end

Class Attribute Details

.dataObject (readonly)

Returns the value of attribute data.



11
12
13
# File 'lib/idcf/cli/lib/util/yml_conf.rb', line 11

def data
  @data
end

Instance Attribute Details

#load_dataObject (readonly)

Returns the value of attribute load_data.



8
9
10
# File 'lib/idcf/cli/lib/util/yml_conf.rb', line 8

def load_data
  @load_data
end

Class Method Details

.load(path) ⇒ Object



12
13
14
15
16
17
# File 'lib/idcf/cli/lib/util/yml_conf.rb', line 12

def load(path)
  @data ||= {}
  return @data[path] unless @data[path].nil?
  @data[path] = name.constantize.new(path)
  @data[path]
end

Instance Method Details

#find(path) ⇒ Object

get config value

Parameters:

  • path (String)
  • section (String)

Returns:

  • String or Hash

Raises:



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/idcf/cli/lib/util/yml_conf.rb', line 33

def find(path)
  result = @load_data
  return result[path] if path.class == Symbol
  path.split('.').each do |name|
    result = result.fetch(name)
  end

  result
rescue StandardError => _e
  raise Idcf::Cli::Error::CliError, "Error: could not read '#{path}'"
end