123456789_123456789_123456789_123456789_123456789_

Class: BiDiGenerate::UnionClass Private

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, Struct
Instance Chain:
self, Struct
Inherits: Struct
  • Object
Defined in: rb/lib/selenium/webdriver/bidi/support/bidi_generate.rb

Overview

A generated discriminated union (< Serialization::Union, resolved by lexical scope). nested holds its synthetic variant records (see nest_synthetic). spec_href links to the union's definition in the live spec (nil when the schema has none). object_only mirrors the schema's objectOnly signal: when true, a non-Hash payload is rejected rather than passed through (every arm is an object, so it can match no variant). scalar_values mirrors the schema's scalarValues signal: the exact literals a bare-scalar arm admits (input.Origin's "viewport" / "pointer"), so outbound rejects any other scalar.

Instance Attribute Summary

  • #discriminator_wire rw Internal use only

    A generated discriminated union (< Serialization::Union, resolved by lexical scope).

  • #inbound rw Internal use only

    A generated discriminated union (< Serialization::Union, resolved by lexical scope).

  • #nested rw Internal use only

    A generated discriminated union (< Serialization::Union, resolved by lexical scope).

  • #object_only rw Internal use only

    A generated discriminated union (< Serialization::Union, resolved by lexical scope).

  • #outbound rw Internal use only

    A generated discriminated union (< Serialization::Union, resolved by lexical scope).

  • #ruby_name rw Internal use only

    A generated discriminated union (< Serialization::Union, resolved by lexical scope).

  • #scalar_values rw Internal use only

    A generated discriminated union (< Serialization::Union, resolved by lexical scope).

  • #scalar_values? ⇒ Boolean rw Internal use only
  • #schema_name rw Internal use only

    A generated discriminated union (< Serialization::Union, resolved by lexical scope).

  • #spec_href rw Internal use only

    A generated discriminated union (< Serialization::Union, resolved by lexical scope).

  • #union? ⇒ Boolean readonly Internal use only
  • #variant_arg_sigs rw Internal use only

    A generated discriminated union (< Serialization::Union, resolved by lexical scope).

  • #variants rw Internal use only

    A generated discriminated union (< Serialization::Union, resolved by lexical scope).

Instance Method Summary

  • #discriminator_decl(indent) Internal use only
    discriminator 'wire', or discriminator 'wire', {sym: 'token', …} (wrapped when long) carrying the inbound wire->symbol map for string-tagged variants.
  • #fallback_variant Internal use only
  • #nested_types Internal use only
  • #presence_variants Internal use only
  • #rbs_value_type Internal use only

    The union's RBS value type — the concrete types a value of this union can actually be: each variant record, plus any bare-scalar arm (input.Origin's "viewport"/"pointer").

  • #rbs_variant_factories Internal use only

    RBS for variant_factories: the variant record's own typed new signature (threaded in as variant_arg_sigs at build time), so a call is checked against the record's fields rather than an opaque splat; the return type pins the concrete variant.

  • #scalar_values_decl Internal use only
    scalar_values 'viewport', 'pointer' — the literals a bare-scalar arm admits.
  • #value_variants Internal use only
  • #variant_factories Internal use only

    A class-method factory per discriminated variant, so a caller builds the right variant record without naming its class or repeating the discriminator: ExtensionData.path(path: '/x') returns ExtensionPath.new(path: '/x').

Instance Attribute Details

#discriminator_wire (rw)

A generated discriminated union (< Serialization::Union, resolved by lexical scope). nested holds its synthetic variant records (see nest_synthetic). spec_href links to the union's definition in the live spec (nil when the schema has none). object_only mirrors the schema's objectOnly signal: when true, a non-Hash payload is rejected rather than passed through (every arm is an object, so it can match no variant). scalar_values mirrors the schema's scalarValues signal: the exact literals a bare-scalar arm admits (input.Origin's "viewport" / "pointer"), so outbound rejects any other scalar.

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/bidi/support/bidi_generate.rb', line 461

UnionClass = Struct.new(:ruby_name, :discriminator_wire, :variants, :schema_name, :nested, :spec_href,
:object_only, :scalar_values, :outbound, :inbound, :variant_arg_sigs,
keyword_init: true)

#inbound (rw)

A generated discriminated union (< Serialization::Union, resolved by lexical scope). nested holds its synthetic variant records (see nest_synthetic). spec_href links to the union's definition in the live spec (nil when the schema has none). object_only mirrors the schema's objectOnly signal: when true, a non-Hash payload is rejected rather than passed through (every arm is an object, so it can match no variant). scalar_values mirrors the schema's scalarValues signal: the exact literals a bare-scalar arm admits (input.Origin's "viewport" / "pointer"), so outbound rejects any other scalar.

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/bidi/support/bidi_generate.rb', line 461

UnionClass = Struct.new(:ruby_name, :discriminator_wire, :variants, :schema_name, :nested, :spec_href,
:object_only, :scalar_values, :outbound, :inbound, :variant_arg_sigs,
keyword_init: true)

#nested (rw)

A generated discriminated union (< Serialization::Union, resolved by lexical scope). nested holds its synthetic variant records (see nest_synthetic). spec_href links to the union's definition in the live spec (nil when the schema has none). object_only mirrors the schema's objectOnly signal: when true, a non-Hash payload is rejected rather than passed through (every arm is an object, so it can match no variant). scalar_values mirrors the schema's scalarValues signal: the exact literals a bare-scalar arm admits (input.Origin's "viewport" / "pointer"), so outbound rejects any other scalar.

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/bidi/support/bidi_generate.rb', line 461

UnionClass = Struct.new(:ruby_name, :discriminator_wire, :variants, :schema_name, :nested, :spec_href,
:object_only, :scalar_values, :outbound, :inbound, :variant_arg_sigs,
keyword_init: true)

#object_only (rw)

A generated discriminated union (< Serialization::Union, resolved by lexical scope). nested holds its synthetic variant records (see nest_synthetic). spec_href links to the union's definition in the live spec (nil when the schema has none). object_only mirrors the schema's objectOnly signal: when true, a non-Hash payload is rejected rather than passed through (every arm is an object, so it can match no variant). scalar_values mirrors the schema's scalarValues signal: the exact literals a bare-scalar arm admits (input.Origin's "viewport" / "pointer"), so outbound rejects any other scalar.

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/bidi/support/bidi_generate.rb', line 461

UnionClass = Struct.new(:ruby_name, :discriminator_wire, :variants, :schema_name, :nested, :spec_href,
:object_only, :scalar_values, :outbound, :inbound, :variant_arg_sigs,
keyword_init: true)

#outbound (rw)

A generated discriminated union (< Serialization::Union, resolved by lexical scope). nested holds its synthetic variant records (see nest_synthetic). spec_href links to the union's definition in the live spec (nil when the schema has none). object_only mirrors the schema's objectOnly signal: when true, a non-Hash payload is rejected rather than passed through (every arm is an object, so it can match no variant). scalar_values mirrors the schema's scalarValues signal: the exact literals a bare-scalar arm admits (input.Origin's "viewport" / "pointer"), so outbound rejects any other scalar.

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/bidi/support/bidi_generate.rb', line 461

UnionClass = Struct.new(:ruby_name, :discriminator_wire, :variants, :schema_name, :nested, :spec_href,
:object_only, :scalar_values, :outbound, :inbound, :variant_arg_sigs,
keyword_init: true)

#ruby_name (rw)

A generated discriminated union (< Serialization::Union, resolved by lexical scope). nested holds its synthetic variant records (see nest_synthetic). spec_href links to the union's definition in the live spec (nil when the schema has none). object_only mirrors the schema's objectOnly signal: when true, a non-Hash payload is rejected rather than passed through (every arm is an object, so it can match no variant). scalar_values mirrors the schema's scalarValues signal: the exact literals a bare-scalar arm admits (input.Origin's "viewport" / "pointer"), so outbound rejects any other scalar.

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/bidi/support/bidi_generate.rb', line 461

UnionClass = Struct.new(:ruby_name, :discriminator_wire, :variants, :schema_name, :nested, :spec_href,
:object_only, :scalar_values, :outbound, :inbound, :variant_arg_sigs,
keyword_init: true)

#scalar_values (rw)

A generated discriminated union (< Serialization::Union, resolved by lexical scope). nested holds its synthetic variant records (see nest_synthetic). spec_href links to the union's definition in the live spec (nil when the schema has none). object_only mirrors the schema's objectOnly signal: when true, a non-Hash payload is rejected rather than passed through (every arm is an object, so it can match no variant). scalar_values mirrors the schema's scalarValues signal: the exact literals a bare-scalar arm admits (input.Origin's "viewport" / "pointer"), so outbound rejects any other scalar.

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/bidi/support/bidi_generate.rb', line 461

UnionClass = Struct.new(:ruby_name, :discriminator_wire, :variants, :schema_name, :nested, :spec_href,
:object_only, :scalar_values, :outbound, :inbound, :variant_arg_sigs,
keyword_init: true)

#scalar_values?Boolean (rw)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/bidi/support/bidi_generate.rb', line 513

def scalar_values? = !(scalar_values.nil? || scalar_values.empty?)

#schema_name (rw)

A generated discriminated union (< Serialization::Union, resolved by lexical scope). nested holds its synthetic variant records (see nest_synthetic). spec_href links to the union's definition in the live spec (nil when the schema has none). object_only mirrors the schema's objectOnly signal: when true, a non-Hash payload is rejected rather than passed through (every arm is an object, so it can match no variant). scalar_values mirrors the schema's scalarValues signal: the exact literals a bare-scalar arm admits (input.Origin's "viewport" / "pointer"), so outbound rejects any other scalar.

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/bidi/support/bidi_generate.rb', line 461

UnionClass = Struct.new(:ruby_name, :discriminator_wire, :variants, :schema_name, :nested, :spec_href,
:object_only, :scalar_values, :outbound, :inbound, :variant_arg_sigs,
keyword_init: true)

#spec_href (rw)

A generated discriminated union (< Serialization::Union, resolved by lexical scope). nested holds its synthetic variant records (see nest_synthetic). spec_href links to the union's definition in the live spec (nil when the schema has none). object_only mirrors the schema's objectOnly signal: when true, a non-Hash payload is rejected rather than passed through (every arm is an object, so it can match no variant). scalar_values mirrors the schema's scalarValues signal: the exact literals a bare-scalar arm admits (input.Origin's "viewport" / "pointer"), so outbound rejects any other scalar.

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/bidi/support/bidi_generate.rb', line 461

UnionClass = Struct.new(:ruby_name, :discriminator_wire, :variants, :schema_name, :nested, :spec_href,
:object_only, :scalar_values, :outbound, :inbound, :variant_arg_sigs,
keyword_init: true)

#union?Boolean (readonly)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/bidi/support/bidi_generate.rb', line 464

def union? = true

#variant_arg_sigs (rw)

A generated discriminated union (< Serialization::Union, resolved by lexical scope). nested holds its synthetic variant records (see nest_synthetic). spec_href links to the union's definition in the live spec (nil when the schema has none). object_only mirrors the schema's objectOnly signal: when true, a non-Hash payload is rejected rather than passed through (every arm is an object, so it can match no variant). scalar_values mirrors the schema's scalarValues signal: the exact literals a bare-scalar arm admits (input.Origin's "viewport" / "pointer"), so outbound rejects any other scalar.

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/bidi/support/bidi_generate.rb', line 461

UnionClass = Struct.new(:ruby_name, :discriminator_wire, :variants, :schema_name, :nested, :spec_href,
:object_only, :scalar_values, :outbound, :inbound, :variant_arg_sigs,
keyword_init: true)

#variants (rw)

A generated discriminated union (< Serialization::Union, resolved by lexical scope). nested holds its synthetic variant records (see nest_synthetic). spec_href links to the union's definition in the live spec (nil when the schema has none). object_only mirrors the schema's objectOnly signal: when true, a non-Hash payload is rejected rather than passed through (every arm is an object, so it can match no variant). scalar_values mirrors the schema's scalarValues signal: the exact literals a bare-scalar arm admits (input.Origin's "viewport" / "pointer"), so outbound rejects any other scalar.

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/bidi/support/bidi_generate.rb', line 461

UnionClass = Struct.new(:ruby_name, :discriminator_wire, :variants, :schema_name, :nested, :spec_href,
:object_only, :scalar_values, :outbound, :inbound, :variant_arg_sigs,
keyword_init: true)

Instance Method Details

#discriminator_decl(indent)

discriminator 'wire', or discriminator 'wire', {sym: 'token', …} (wrapped when long) carrying the inbound wire->symbol map for string-tagged variants.

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/bidi/support/bidi_generate.rb', line 505

def discriminator_decl(indent)
  pairs = value_variants.filter_map(&:discriminator_pair)
  head = "discriminator '#{discriminator_wire}'"
  return head if pairs.empty?

  BiDiGenerate.wrap_call("#{head}, ", pairs, indent, open: '{', close: '}')
end

#fallback_variant

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/bidi/support/bidi_generate.rb', line 467

def fallback_variant = variants.find { |v| v.mode == :fallback }

#nested_types

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/bidi/support/bidi_generate.rb', line 468

def nested_types = nested || []

#presence_variants

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/bidi/support/bidi_generate.rb', line 466

def presence_variants = variants.select { |v| v.mode == :presence }

#rbs_value_type

The union's RBS value type — the concrete types a value of this union can actually be: each variant record, plus any bare-scalar arm (input.Origin's "viewport"/"pointer"). The union class itself has no instances, so this alias (not the class) is what a field, param, or result of the union is typed to, letting a variant pass where the union is expected.

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/bidi/support/bidi_generate.rb', line 496

def rbs_value_type
  refs = (value_variants + presence_variants + [fallback_variant].compact).map(&:ref).uniq
  parts = refs.map { |ref| "::Selenium::WebDriver::BiDi::Protocol::#{ref}" }
  parts += Array(scalar_values).map { |value| value.is_a?(::String) ? value.inspect : value.to_s }
  parts.empty? ? 'untyped' : parts.join(' | ')
end

#rbs_variant_factories

RBS for variant_factories: the variant record's own typed new signature (threaded in as variant_arg_sigs at build time), so a call is checked against the record's fields rather than an opaque splat; the return type pins the concrete variant.

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/bidi/support/bidi_generate.rb', line 484

def rbs_variant_factories
  value_variants.map do |variant|
    args = (variant_arg_sigs || {})[BiDiGenerate.enum_key(variant.value)] || '**untyped'
    "def self.#{BiDiGenerate.enum_key(variant.value)}: (#{args}) " \
      "-> ::Selenium::WebDriver::BiDi::Protocol::#{variant.ref}"
  end
end

#scalar_values_decl

scalar_values 'viewport', 'pointer' — the literals a bare-scalar arm admits.

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/bidi/support/bidi_generate.rb', line 516

def scalar_values_decl
  "scalar_values #{scalar_values.map { |v| BiDiGenerate.ruby_literal(v) }.join(', ')}"
end

#value_variants

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/bidi/support/bidi_generate.rb', line 465

def value_variants = variants.select { |v| v.mode == :value }

#variant_factories

A class-method factory per discriminated variant, so a caller builds the right variant record without naming its class or repeating the discriminator: ExtensionData.path(path: '/x') returns ExtensionPath.new(path: '/x'). The method name is the variant's discriminator symbol; every value variant's ref is a record, so .new is always defined. Presence/fallback arms are omitted (no single tag to name).

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/bidi/support/bidi_generate.rb', line 475

def variant_factories
  value_variants.map do |variant|
    "def self.#{BiDiGenerate.enum_key(variant.value)}(**) = #{variant.ref}.new(**)"
  end
end