Class: Asimov::Utils::RequestOptionsValidator
- Inherits:
-
Object
- Object
- Asimov::Utils::RequestOptionsValidator
- Defined in:
- lib/asimov/utils/request_options_validator.rb
Overview
Validates a set of request options that are passed to the application configuration or on Asimov::Client initialization. Ensures that the value is a hash, that all keys are symbols, and that all keys correspond to legitimate options (typically relating to network behavior). Currently does not validate the option values.
Constant Summary collapse
- ALLOWED_OPTIONS =
This is taken from HTTParty
%i[timeout open_timeout read_timeout write_timeout local_host local_port verify verify_peer ssl_ca_file ssl_ca_path ssl_version ciphers http_proxyaddr http_proxyport http_proxyuser http_proxypass].freeze
Class Method Summary collapse
- .check_symbol(key) ⇒ Object
- .check_unsupported_options(unsupported_options) ⇒ Object
- .generate_unsupported_options(options) ⇒ Object
- .supported_option?(key) ⇒ Boolean
- .validate(options) ⇒ Object
Class Method Details
.check_symbol(key) ⇒ Object
48 49 50 51 52 53 |
# File 'lib/asimov/utils/request_options_validator.rb', line 48 def self.check_symbol(key) return if key.is_a?(Symbol) raise Asimov::ConfigurationError, "Request options keys must be symbols. The key '#{key}' is not a symbol." end |
.check_unsupported_options(unsupported_options) ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/asimov/utils/request_options_validator.rb', line 36 def self.() return if .empty? quoted_keys = .map { |k| "'#{k}'" } raise Asimov::ConfigurationError, "The options #{quoted_keys.join(',')} are not supported." end |
.generate_unsupported_options(options) ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/asimov/utils/request_options_validator.rb', line 27 def self.() = [] .each_key do |k| check_symbol(k) << k unless supported_option?(k) end end |
.supported_option?(key) ⇒ Boolean
44 45 46 |
# File 'lib/asimov/utils/request_options_validator.rb', line 44 def self.supported_option?(key) ALLOWED_OPTIONS.include?(key) end |
.validate(options) ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/asimov/utils/request_options_validator.rb', line 17 def self.validate() unless .is_a?(Hash) raise Asimov::ConfigurationError, "Request options must be a hash" end (()) end |