Class: Bucky::Utils::Config

Inherits:
Object
  • Object
show all
Includes:
YamlLoad, Singleton
Defined in:
lib/bucky/utils/config.rb

Constant Summary collapse

@@dir =
"#{$bucky_home_dir}/config/**/*yml"

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from YamlLoad

#file_sort_hierarchy, #load_yaml

Constructor Details

#initializeConfig

Returns a new instance of Config.

Parameters:

  • *.yml (String)

    or hoge/fuga.yml



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/bucky/utils/config.rb', line 15

def initialize
  @data = {}
  @resources = []
  @default_config_dir = File.expand_path('../../../template/new/config', __dir__)

  # Read from a file of shallow hierarchy, then overwrite it if there is same key in deep hierarchy
  file_sort_hierarchy(@@dir).each do |file|
    file_name = file.split('/').last
    default_config_file = @default_config_dir + '/' + file_name
    data = load_yaml(file)
    next if data.empty?

    if File.exist?(default_config_file)
      default_config_data = load_yaml(default_config_file)
      data = default_config_data.merge(data)
    end
    @data = @data.merge(data)
    @resources << file
  end

  set_selenium_ip
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



13
14
15
# File 'lib/bucky/utils/config.rb', line 13

def data
  @data
end

Instance Method Details

#[](column) ⇒ Object

Get data by []



39
40
41
42
43
44
# File 'lib/bucky/utils/config.rb', line 39

def [](column)
  return @data[column] if @data.key?(column)

  # If there is no key, raise exeption
  raise "Undefined Config : #{column}\nKey doesn't match in config file. Please check config file in config/*"
end