Class: Coffeebrew::Jekyll::Archives::Validator

Inherits:
Object
  • Object
show all
Defined in:
lib/coffeebrew_jekyll_archives/validator.rb

Constant Summary collapse

ALLOWED_CONFIG_KEYS =
{
  "navigation" => {
    "data" => [],
    "name" => [],
    "before" => [],
    "after" => []
  },
  "depths" => [1, 2, 3],
  "title_format" => {
    "root" => {
      "type" => %w[string date],
      "style" => []
    },
    "year" => {
      "type" => %w[string date],
      "style" => []
    },
    "month" => {
      "type" => %w[string date],
      "style" => []
    },
    "day" => {
      "type" => %w[string date],
      "style" => []
    }
  },
  "root_dir" => [],
  "root_basename" => [],
  "index_root" => [],
  "index_basename" => [],
  "permalink" => {
    "root" => [],
    "year" => [],
    "month" => [],
    "day" => []
  }
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Validator

Returns a new instance of Validator.



45
46
47
48
# File 'lib/coffeebrew_jekyll_archives/validator.rb', line 45

def initialize(config)
  @config = config
  @errors = []
end

Instance Method Details

#validate!Object

Raises:

  • (::Jekyll::Errors::InvalidConfigurationError)


50
51
52
53
54
55
56
57
58
59
# File 'lib/coffeebrew_jekyll_archives/validator.rb', line 50

def validate!
  parse(@config, ALLOWED_CONFIG_KEYS, ["archives"])

  return if @errors.empty?

  ::Jekyll.logger.error "'archives' config is set incorrectly."
  ::Jekyll.logger.error "Errors:", @errors

  raise ::Jekyll::Errors::InvalidConfigurationError, "'archives' config is set incorrectly."
end