Class: Selenium::WebDriver::BiDi::Serialization::Union Private
- Inherits:
-
Object
- Object
- Selenium::WebDriver::BiDi::Serialization::Union
- Defined in:
- lib/selenium/webdriver/bidi/serialization/union.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Resolves a wire payload to the right Data variant: a shared discriminator gives table dispatch; presence rules and a no-tag fallback cover unions without one. Subclassed (never instantiated) — each union holds its own dispatch table.
class Locator < Serialization::Union
discriminator 'type'
variants('css' => 'BrowsingContext::CssLocator')
end
Direct Known Subclasses
Protocol::Bluetooth::HandleRequestDevicePromptParameters, Protocol::Browser::DownloadBehavior, Protocol::Browser::SetClientWindowStateParameters, Protocol::BrowsingContext::ClipRectangle, Protocol::BrowsingContext::DownloadEndParams, Protocol::BrowsingContext::Locator, Protocol::Emulation::SetGeolocationOverrideParameters, Protocol::Input::KeySourceAction, Protocol::Input::Origin, Protocol::Input::PointerSourceAction, Protocol::Input::SourceActions, Protocol::Input::WheelSourceAction, Protocol::Log::Entry, Protocol::Network::BytesValue, Protocol::Network::ContinueWithAuthParameters, Protocol::Network::UrlPattern, Protocol::Script::EvaluateResult, Protocol::Script::LocalValue, Protocol::Script::PrimitiveProtocolValue, Protocol::Script::RealmInfo, Protocol::Script::RemoteReference, Protocol::Script::RemoteValue, Protocol::Script::Target, Protocol::Session::ProxyConfiguration, Protocol::Session::UnsubscribeParameters, Protocol::Storage::PartitionDescriptor, Protocol::WebExtension::ExtensionData
Class Method Summary collapse
-
.build(**kwargs) ⇒ Object
private
Outbound mirror of from_json: build the variant the command's kwargs describe so its typed as_json drives null-vs-absent per field (a flat hash through Transport cannot).
-
.discriminator(wire_key, values = {}) ⇒ Object
private
values maps each variant's discriminator symbol to its wire token, so an inbound payload tag (a wire string) can be matched to the symbol-keyed table.
- .fallback(path) ⇒ Object private
-
.from_json(json_payload) ⇒ Object
private
A non-Hash payload is a bare scalar arm (e.g. input.Origin's "viewport") with no object to dispatch on, so it is returned unchanged.
- .presence(rules) ⇒ Object private
- .variants(table) ⇒ Object private
Class Method Details
.build(**kwargs) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Outbound mirror of from_json: build the variant the command's kwargs describe so its typed as_json drives null-vs-absent per field (a flat hash through Transport cannot). Dispatch keys are wire names equal to their ruby kwarg (asserted at generation), so they match the kwargs by symbol. A mismatch here is a caller error (unlike an unknown inbound value), so it fails loudly.
65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/selenium/webdriver/bidi/serialization/union.rb', line 65 def build(**kwargs) variant = outbound_variant(kwargs) || raise(::ArgumentError, "no #{name} variant matches #{kwargs.inspect}") klass = Protocol.const_get(variant) # An omitted optional arrives as UNSET; forward only what was provided. A provided # key that isn't a field of the chosen variant is an invalid combination for this union. provided = kwargs.reject { |_, value| UNSET.equal?(value) } invalid = provided.keys - klass.fields.map(&:name) return klass.new(**provided) if invalid.empty? raise ::ArgumentError, "invalid combination for #{name}: #{invalid.join(', ')}" end |
.discriminator(wire_key, values = {}) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
values maps each variant's discriminator symbol to its wire token, so an inbound payload tag (a wire string) can be matched to the symbol-keyed table.
38 39 40 41 |
# File 'lib/selenium/webdriver/bidi/serialization/union.rb', line 38 def discriminator(wire_key, values = {}) @discriminator = wire_key @discriminator_values = values end |
.fallback(path) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
45 |
# File 'lib/selenium/webdriver/bidi/serialization/union.rb', line 45 def fallback(path) = @fallback = path |
.from_json(json_payload) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
A non-Hash payload is a bare scalar arm (e.g. input.Origin's "viewport") with no object to dispatch on, so it is returned unchanged.
49 50 51 52 53 54 55 56 57 58 |
# File 'lib/selenium/webdriver/bidi/serialization/union.rb', line 49 def from_json(json_payload) return json_payload unless json_payload.is_a?(::Hash) variant = select(json_payload) unless variant raise Error::WebDriverError, "#{name} received a variant not in this Selenium's BiDi schema: #{json_payload.inspect}" end Protocol.const_get(variant).from_json(json_payload) end |
.presence(rules) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
44 |
# File 'lib/selenium/webdriver/bidi/serialization/union.rb', line 44 def presence(rules) = @presence = rules |
.variants(table) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
43 |
# File 'lib/selenium/webdriver/bidi/serialization/union.rb', line 43 def variants(table) = @variants = table |