class Bucky::Utils::Config

Attributes

data[R]

Public Class Methods

new() click to toggle source

@param [String] *.yml or hoge/fuga.yml

# 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

Public Instance Methods

[](column) click to toggle source

Get data by []

# 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

Private Instance Methods

set_selenium_ip() click to toggle source
# File lib/bucky/utils/config.rb, line 48
def set_selenium_ip
  return unless @data[:selenium_ip] == 'docker_host_ip'

  selenium_ip = `ip route | awk 'NR==1 {print $3}'`.chomp
  raise StandardError, 'Could not load docker host ip.' if selenium_ip.empty?

  @data[:selenium_ip] = selenium_ip
end