Class: Html2rss::Config::Validator

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

Overview

Validates the configuration hash using Dry::Validation. The configuration options adhere to the documented schema in README.md.

Constant Summary collapse

URI_REGEXP =

URI format used for channel URL validation.

Url::URI_REGEXP
STYLESHEET_TYPES =

Allowed stylesheet MIME types.

FeedBuilder::Rss::Stylesheet::TYPES
LANGUAGE_FORMAT_REGEX =

Optional language/region format (en or en-US).

/\A[a-z]{2}(-[A-Z]{2})?\z/
BASE_STRATEGY_OPTIONS =

Baseline strategy-plan enum (:auto plus concrete RequestService strategies).

Html2rss::FeedPipeline::StrategyPlan.accepted_names.freeze
DIRECTORY_TOPICS =

Controlled vocabulary for catalog-only directory.topics (not RSS channel fields).

%w[
  sports energy tech science news entertainment jobs finance
  security travel environment consumer civic product research
].freeze
ChannelConfig =

Contract for the top-level channel section.

Dry::Schema.Params do
  required(:url).filled(:string, format?: URI_REGEXP)
  optional(:title).maybe(:string)
  optional(:description).maybe(:string)
  optional(:language).maybe(:string, format?: LANGUAGE_FORMAT_REGEX)
  optional(:ttl).maybe(:integer, gt?: 0)
  optional(:time_zone).maybe(:string)
  optional(:author).maybe(:string)
  optional(:image).maybe(:string, format?: URI_REGEXP)
end
DirectoryConfig =

Contract for catalog-only directory metadata (topics for feed directories).

Dry::Schema.Params do
  optional(:topics).value(:array, min_size?: 1).each(:string, included_in?: DIRECTORY_TOPICS)
end
StylesheetConfig =

Contract for a stylesheet entry in stylesheets.

Dry::Schema.Params do
  required(:href).filled(:string)
  required(:type).filled(:string, included_in?: STYLESHEET_TYPES)
  optional(:media).maybe(:string)
end
BotasaurusRequestConfig =

Contract for Botasaurus-specific request options.

Dry::Schema.Params do
  config.validate_keys = true

  optional(:execution_mode).filled(:string, included_in?: %w[auto request browser])
  optional(:navigation_mode).filled(:string, included_in?: %w[auto get google_get google_get_bypass organic_get])
  optional(:max_retries).filled(:integer, gteq?: 0, lteq?: 3)
  optional(:wait_for_selector).maybe(:string)
  optional(:wait_timeout_seconds).filled(:integer, gt?: 0)
  optional(:scroll).filled(:bool)
  optional(:scroll_to_bottom).filled(:bool)
  optional(:block_images).filled(:bool)
  optional(:block_images_and_css).filled(:bool)
  optional(:block_trackers).filled(:bool)
  optional(:wait_for_complete_page_load).filled(:bool)
  optional(:headless).filled(:bool)
  optional(:proxy).filled(:string)
  optional(:user_agent).filled(:string)
  optional(:window_size).value(:array, min_size?: 2, max_size?: 2).each(:integer, gt?: 0)
  optional(:lang).filled(:string)
  optional(:cookies).hash
  optional(:headers).hash
end
RequestConfig =

Contract for the top-level request section.

Dry::Schema.Params do
  optional(:max_redirects).filled(:integer, gteq?: 0)
  optional(:max_requests).filled(:integer, gt?: 0)
  optional(:total_timeout_seconds).filled(:integer, gt?: 0)
  optional(:botasaurus).hash(BotasaurusRequestConfig)
  optional(:local_file_path).filled(:string)
end