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.

RssBuilder::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 enum exported in static schema artifacts.

([:auto] + Html2rss::RequestService.strategy_names.map(&:to_sym)).uniq.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)
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
BrowserlessPreloadClickSelectorConfig =

Contract for Browserless click-preload options.

Dry::Schema.Params do
  required(:selector).filled(:string)
  optional(:max_clicks).filled(:integer, gt?: 0)
  optional(:wait_after_ms).filled(:integer, gteq?: 0)
end
BrowserlessPreloadScrollConfig =

Contract for Browserless scroll-preload options.

Dry::Schema.Params do
  optional(:iterations).filled(:integer, gt?: 0)
  optional(:wait_after_ms).filled(:integer, gteq?: 0)
end
BrowserlessPreloadConfig =

Contract for Browserless preload orchestration options.

Dry::Schema.Params do
  optional(:wait_after_ms).filled(:integer, gteq?: 0)
  optional(:click_selectors).array(BrowserlessPreloadClickSelectorConfig)
  optional(:scroll_down).hash(BrowserlessPreloadScrollConfig)
end
BrowserlessRequestConfig =

Contract for Browserless-specific request options.

Dry::Schema.Params do
  optional(:preload).hash(BrowserlessPreloadConfig)
end
BotasaurusRequestConfig =

Contract for Botasaurus-specific request options.

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

  optional(:navigation_mode).filled(:string, included_in?: %w[auto get google_get google_get_bypass])
  optional(:max_retries).filled(:integer, gteq?: 0, lteq?: 3)
  optional(:wait_for_selector).maybe(:string)
  optional(:wait_timeout_seconds).filled(:integer, gt?: 0)
  optional(:block_images).filled(:bool)
  optional(:block_images_and_css).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)
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(:browserless).hash(BrowserlessRequestConfig)
  optional(:botasaurus).hash(BotasaurusRequestConfig)
end