Module: CommonMarker::Config

Defined in:
lib/commonmarker/config.rb

Overview

For Ruby::Enum, these must be classes, not modules

Defined Under Namespace

Classes: Parse, Render

Class Method Summary collapse

Class Method Details

.check_option(option, type) ⇒ Object



37
38
39
40
41
# File 'lib/commonmarker/config.rb', line 37

def self.check_option(option, type)
  unless type.keys.include?(option)
    fail TypeError, "option ':#{option}' does not exist for #{type}"
  end
end

.process_options(option, type) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/commonmarker/config.rb', line 23

def self.process_options(option, type)
  type = Config.const_get(type.capitalize)
  if option.is_a?(Symbol)
    check_option(option, type)
    type.to_h[option]
  elsif option.is_a?(Array)
    option = [nil] if option.empty?
    # neckbearding around. the map will both check the opts and then bitwise-OR it
    option.map { |o| check_option(o, type); type.to_h[o] }.inject(0, :|)
  else
    fail TypeError, 'option type must be a valid symbol or array of symbols'
  end
end