class BigFiles::ConfigFileParser

Load configuration from files

Attributes

project_config_filename[R]

Public Class Methods

new(project_config_filename = '.bigfiles.yml', yaml_class: YAML, file_class: File) click to toggle source
# File lib/bigfiles/config_file_parser.rb, line 10
def initialize(project_config_filename = '.bigfiles.yml',
               yaml_class: YAML,
               file_class: File)
  @project_config_filename = project_config_filename
  @yaml_class = yaml_class
  @file_class = file_class
end

Public Instance Methods

parse_config_files() click to toggle source
# File lib/bigfiles/config_file_parser.rb, line 18
def parse_config_files
  config = {}
  project_config = parse_project_config
  config.merge(project_config)
end

Private Instance Methods

item(raw_project_config, section, key) click to toggle source
# File lib/bigfiles/config_file_parser.rb, line 26
def item(raw_project_config, section, key)
  raw_project_config.fetch('bigfiles', {}).fetch(section, {}).fetch(key, nil)
end
parse_project_config() click to toggle source
# File lib/bigfiles/config_file_parser.rb, line 34
def parse_project_config
  return {} unless @file_class.file? project_config_filename

  project_config = {}
  raw_project_config = @yaml_class.load_file(project_config_filename)
  exclude = item(raw_project_config, 'exclude', 'glob')
  project_config[:exclude] = exclude unless exclude.nil?
  glob = item(raw_project_config, 'include', 'glob')
  project_config[:glob] = glob unless glob.nil?
  num_files = top_item(raw_project_config, 'num_files')
  project_config[:num_files] = num_files unless num_files.nil?
  project_config
end
top_item(raw_project_config, key) click to toggle source
# File lib/bigfiles/config_file_parser.rb, line 30
def top_item(raw_project_config, key)
  raw_project_config.fetch('bigfiles', {}).fetch(key, nil)
end