Class: URLCanonicalize::Options

Inherits:
Object
  • Object
show all
Defined in:
lib/url_canonicalize/options.rb

Overview

Validated configuration for one canonicalization operation

Constant Summary collapse

DEFAULTS =
{
  allow_private_networks: false,
  allowed_ports: [80, 443].freeze,
  headers: {
    'Accept-Language' => 'en-US,en;q=0.8',
    'User-Agent' => 'Mozilla/5.0 (Windows NT 10.0; WOW64) ' \
                    'AppleWebKit/537.36 (KHTML, like Gecko) ' \
                    'Chrome/51.0.2704.103 Safari/537.36'
  }.freeze,
  logger: nil,
  max_body_bytes: 1_048_576,
  total_timeout: 30,
  open_timeout: 8,
  read_timeout: 15,
  write_timeout: 8,
  max_redirects: 10,
  transport: Transport.new
}.freeze
POSITIVE_NUMERIC_OPTIONS =
%i[total_timeout open_timeout read_timeout write_timeout].freeze
POSITIVE_INTEGER_OPTIONS =
%i[max_body_bytes max_redirects].freeze

Instance Method Summary collapse

Constructor Details

#initialize(**values) ⇒ Options

Returns a new instance of Options.



28
29
30
31
32
33
34
35
36
37
# File 'lib/url_canonicalize/options.rb', line 28

def initialize(**values)
  validate_known_options!(values)

  @values = DEFAULTS.merge(values)
  validate!
  @values[:allowed_ports] = @values[:allowed_ports].dup.freeze
  @values[:headers] = @values[:headers].dup.freeze
  @values.freeze
  freeze
end

Instance Method Details

#[](key) ⇒ Object



39
40
41
# File 'lib/url_canonicalize/options.rb', line 39

def [](key)
  @values.fetch(key)
end

#to_hObject



43
44
45
# File 'lib/url_canonicalize/options.rb', line 43

def to_h
  @values.merge(allowed_ports: @values[:allowed_ports].dup, headers: @values[:headers].dup)
end