Class: Html2rss::Selectors::Config

Inherits:
Dry::Validation::Contract
  • Object
show all
Defined in:
lib/html2rss/selectors/config.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



114
115
116
117
118
119
120
# File 'lib/html2rss/selectors/config.rb', line 114

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