class MrPoole::Config

Public Class Methods

new() click to toggle source
# File lib/mr_poole/config.rb, line 18
def initialize
  begin
    if File.exists?('_config.yml')
      yaml = YAML.load(File.read('_config.yml'))
      @config = OpenStruct.new(yaml["poole"])
      @config.srcdir = yaml['source'] if yaml['source']
      check_word_separator
    else
      @config = OpenStruct.new
    end
  rescue TypeError, ::Psych::SyntaxError
    bad_yaml_message
    exit
  end
end

Public Instance Methods

empty?() click to toggle source
# File lib/mr_poole/config.rb, line 34
def empty?
  @config == OpenStruct.new
end
inspect() click to toggle source
# File lib/mr_poole/config.rb, line 38
def inspect
  @config.inspect
end
method_missing(sym, *args) click to toggle source
# File lib/mr_poole/config.rb, line 42
def method_missing(sym, *args)
  @config.send(sym)
end

Private Instance Methods

bad_yaml_message() click to toggle source
# File lib/mr_poole/config.rb, line 59
def bad_yaml_message
  puts 'Error reading YAML file _config.yml!'
  puts '  (Did you forget to escape a hyphen?)'
end
check_word_separator() click to toggle source

on old rubies, the YAML parser doesn’t throw an error if you pass something like ‘word_separator: -’, it just assumes you want an array with the elment nil. We’ll check for that case and die, since it’s not what we want here.

# File lib/mr_poole/config.rb, line 52
def check_word_separator
  return unless @config.word_separator
  if @config.word_separator == [nil]
    raise TypeError
  end
end