Class: Html2rss::Config::RequestControls
- Inherits:
-
Object
- Object
- Html2rss::Config::RequestControls
- Defined in:
- lib/html2rss/config/request_controls.rb
Overview
Wire provenance for request control values (explicit vs default).
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
requestconfig. %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_cli_options(strategy:, max_redirects: nil, max_requests: nil) ⇒ RequestControls
Builds controls from CLI option values.
-
.from_config(config) ⇒ RequestControls
Request controls extracted from the config hash.
-
.from_shortcut(strategy:, max_redirects: nil, max_requests: nil) ⇒ RequestControls
Builds controls for public API shortcuts (Html2rss.auto_source, etc.).
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.
87 88 89 90 91 92 93 94 95 |
# File 'lib/html2rss/config/request_controls.rb', line 87 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.
103 104 105 |
# File 'lib/html2rss/config/request_controls.rb', line 103 def max_redirects @max_redirects end |
#max_requests ⇒ Integer? (readonly)
Returns effective request budget.
107 108 109 |
# File 'lib/html2rss/config/request_controls.rb', line 107 def max_requests @max_requests end |
#strategy ⇒ Symbol? (readonly)
Returns effective request strategy.
99 100 101 |
# File 'lib/html2rss/config/request_controls.rb', line 99 def strategy @strategy end |
#total_timeout_seconds ⇒ Integer? (readonly)
Returns effective request timeout.
111 112 113 |
# File 'lib/html2rss/config/request_controls.rb', line 111 def total_timeout_seconds @total_timeout_seconds end |
Class Method Details
.from_cli_options(strategy:, max_redirects: nil, max_requests: nil) ⇒ RequestControls
Builds controls from CLI option values. Strategy is explicit when the option was provided (truthy string/symbol), matching Thor option presence.
70 71 72 73 74 75 76 77 |
# File 'lib/html2rss/config/request_controls.rb', line 70 def self.(strategy:, max_redirects: nil, max_requests: nil) strategy_sym = strategy&.to_sym keys = [] keys << :strategy if strategy keys << :max_redirects unless max_redirects.nil? keys << :max_requests unless max_requests.nil? new(strategy: strategy_sym, max_redirects:, max_requests:, explicit_keys: keys) end |
.from_config(config) ⇒ RequestControls
Returns request controls extracted from the config hash.
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/html2rss/config/request_controls.rb', line 16 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 |
.from_shortcut(strategy:, max_redirects: nil, max_requests: nil) ⇒ RequestControls
Builds controls for public API shortcuts (Html2rss.auto_source, etc.). Strategy is explicit only when non-nil and not the configured default.
54 55 56 57 58 59 60 |
# File 'lib/html2rss/config/request_controls.rb', line 54 def self.from_shortcut(strategy:, max_redirects: nil, max_requests: nil) keys = [] keys << :strategy unless strategy.nil? || strategy == Config.default_strategy_name keys << :max_redirects unless max_redirects.nil? keys << :max_requests unless max_requests.nil? new(strategy:, max_redirects:, max_requests:, explicit_keys: keys) end |
Instance Method Details
#apply_to(config) ⇒ Hash{Symbol => Object}
Applies only explicitly set controls to the provided config hash.
141 142 143 144 145 146 147 |
# File 'lib/html2rss/config/request_controls.rb', line 141 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.
116 117 118 |
# File 'lib/html2rss/config/request_controls.rb', line 116 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.
126 127 128 129 130 131 132 133 134 |
# File 'lib/html2rss/config/request_controls.rb', line 126 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 |