Class: Html2rss::RequestControls
- Inherits:
-
Object
- Object
- Html2rss::RequestControls
- Defined in:
- lib/html2rss/request_controls.rb
Overview
Tracks runtime request controls together with whether each value was explicitly set.
Constant Summary collapse
- TOP_LEVEL_KEYS =
Request-control keys accepted at the top level of feed config.
%i[strategy].freeze
- REQUEST_KEYS =
Request-control keys accepted under the nested ‘request` config.
%i[max_redirects max_requests total_timeout_seconds].freeze
Instance Attribute Summary collapse
-
#max_redirects ⇒ Integer?
readonly
Effective redirect limit.
-
#max_requests ⇒ Integer?
readonly
Effective request budget.
-
#strategy ⇒ Symbol?
readonly
Effective request strategy.
-
#total_timeout_seconds ⇒ Integer?
readonly
Effective request timeout.
Class Method Summary collapse
-
.from_config(config) ⇒ RequestControls
Request controls extracted from the config hash.
Instance Method Summary collapse
-
#apply_to(config) ⇒ Hash{Symbol => Object}
Applies only explicitly set controls to the provided config hash.
-
#explicit?(name) ⇒ Boolean
Whether the control was explicitly supplied.
-
#initialize(strategy: nil, max_redirects: nil, max_requests: nil, total_timeout_seconds: nil, explicit_keys: []) ⇒ RequestControls
constructor
A new instance of RequestControls.
-
#with_effective_values(strategy:, max_redirects:, max_requests:, total_timeout_seconds:) ⇒ RequestControls
Controls updated with validated effective values.
Constructor Details
#initialize(strategy: nil, max_redirects: nil, max_requests: nil, total_timeout_seconds: nil, explicit_keys: []) ⇒ RequestControls
Returns a new instance of RequestControls.
53 54 55 56 57 58 59 60 |
# File 'lib/html2rss/request_controls.rb', line 53 def initialize(strategy: nil, max_redirects: nil, max_requests: nil, total_timeout_seconds: nil, explicit_keys: []) @strategy = strategy @max_redirects = max_redirects @max_requests = max_requests @total_timeout_seconds = total_timeout_seconds @explicit_keys = explicit_keys.map(&:to_sym).uniq.freeze freeze end |
Instance Attribute Details
#max_redirects ⇒ Integer? (readonly)
Returns effective redirect limit.
68 69 70 |
# File 'lib/html2rss/request_controls.rb', line 68 def max_redirects @max_redirects end |
#max_requests ⇒ Integer? (readonly)
Returns effective request budget.
72 73 74 |
# File 'lib/html2rss/request_controls.rb', line 72 def max_requests @max_requests end |
#strategy ⇒ Symbol? (readonly)
Returns effective request strategy.
64 65 66 |
# File 'lib/html2rss/request_controls.rb', line 64 def strategy @strategy end |
#total_timeout_seconds ⇒ Integer? (readonly)
Returns effective request timeout.
76 77 78 |
# File 'lib/html2rss/request_controls.rb', line 76 def total_timeout_seconds @total_timeout_seconds end |
Class Method Details
.from_config(config) ⇒ RequestControls
Returns request controls extracted from the config hash.
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/html2rss/request_controls.rb', line 15 def self.from_config(config) HashUtil.assert_symbol_keys!(config, context: 'config', deep: false) HashUtil.assert_symbol_keys!(config[:request], context: 'config[:request]') if config[:request].is_a?(Hash) new( strategy: config[:strategy], max_redirects: request_value_for(config, :max_redirects), max_requests: request_value_for(config, :max_requests), total_timeout_seconds: request_value_for(config, :total_timeout_seconds), explicit_keys: explicit_keys_for(config) ) end |
Instance Method Details
#apply_to(config) ⇒ Hash{Symbol => Object}
Applies only explicitly set controls to the provided config hash.
106 107 108 109 110 111 112 |
# File 'lib/html2rss/request_controls.rb', line 106 def apply_to(config) config[:strategy] = strategy if explicit?(:strategy) apply_request_value(config, :max_redirects, max_redirects) apply_request_value(config, :max_requests, max_requests) apply_request_value(config, :total_timeout_seconds, total_timeout_seconds) config end |
#explicit?(name) ⇒ Boolean
Returns whether the control was explicitly supplied.
81 82 83 |
# File 'lib/html2rss/request_controls.rb', line 81 def explicit?(name) explicit_keys.include?(name.to_sym) end |
#with_effective_values(strategy:, max_redirects:, max_requests:, total_timeout_seconds:) ⇒ RequestControls
Returns controls updated with validated effective values.
91 92 93 94 95 96 97 98 99 |
# File 'lib/html2rss/request_controls.rb', line 91 def with_effective_values(strategy:, max_redirects:, max_requests:, total_timeout_seconds:) self.class.new( strategy:, max_redirects:, max_requests:, total_timeout_seconds:, explicit_keys: ) end |