Class: Html2rss::Config::SelectorsValidator

Inherits:
Dry::Validation::Contract
  • Object
show all
Defined in:
lib/html2rss/config/selectors_validator.rb

Overview

Validates the configuration hash for :selectors.

Defined Under Namespace

Classes: Enclosure, Items, Selector

Constant Summary collapse

NESTING_KEY =

Required wrapper key used to validate dynamic selector names.

:dynamic_keys_workaround

Class Method Summary collapse

Class Method Details

.call(config) ⇒ Dry::Validation::Result

Shortcut to validate the config.

Parameters:

  • config (Hash)

    the configuration hash to validate

Returns:

  • (Dry::Validation::Result)

    the result of the validation



163
164
165
166
167
168
169
# File 'lib/html2rss/config/selectors_validator.rb', line 163

def self.call(config)
  # dry-validation/schema does not support "Dynamic Keys" yet: https://github.com/dry-rb/dry-schema/issues/37
  # But :selectors contains mostly "dynamic" keys, as the user defines them to extract article attributes.
  # --> Validate the dynamic keys manually.
  # To be able to specify a `rule`, nest the config under NESTING_KEY and mark that as `required`.
  new.call(NESTING_KEY => config)
end