Class: BiDiGenerate::UnionClass Private

Inherits:
Struct
  • Object
show all
Defined in:
lib/selenium/webdriver/bidi/support/bidi_generate.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.

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 collapse

Instance Method Summary collapse

Instance Attribute Details

#discriminator_wireObject

Returns the value of attribute discriminator_wire

Returns:

  • (Object)

    the current value of discriminator_wire



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

def discriminator_wire
  @discriminator_wire
end

#inboundObject

Returns the value of attribute inbound

Returns:

  • (Object)

    the current value of inbound



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

def inbound
  @inbound
end

#nestedObject

Returns the value of attribute nested

Returns:

  • (Object)

    the current value of nested



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

def nested
  @nested
end

#object_onlyObject

Returns the value of attribute object_only

Returns:

  • (Object)

    the current value of object_only



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

def object_only
  @object_only
end

#outboundObject

Returns the value of attribute outbound

Returns:

  • (Object)

    the current value of outbound



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

def outbound
  @outbound
end

#ruby_nameObject

Returns the value of attribute ruby_name

Returns:

  • (Object)

    the current value of ruby_name



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

def ruby_name
  @ruby_name
end

#scalar_valuesObject

Returns the value of attribute scalar_values

Returns:

  • (Object)

    the current value of scalar_values



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

def scalar_values
  @scalar_values
end

#schema_nameObject

Returns the value of attribute schema_name

Returns:

  • (Object)

    the current value of schema_name



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

def schema_name
  @schema_name
end

#spec_hrefObject

Returns the value of attribute spec_href

Returns:

  • (Object)

    the current value of spec_href



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

def spec_href
  @spec_href
end

#variant_arg_sigsObject

Returns the value of attribute variant_arg_sigs

Returns:

  • (Object)

    the current value of variant_arg_sigs



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

def variant_arg_sigs
  @variant_arg_sigs
end

#variantsObject

Returns the value of attribute variants

Returns:

  • (Object)

    the current value of variants



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

def variants
  @variants
end

Instance Method Details

#discriminator_decl(indent) ⇒ 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.

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



505
506
507
508
509
510
511
# File '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_variantObject

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.



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

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

#nested_typesObject

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.



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

def nested_types = nested || []

#presence_variantsObject

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.



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

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

#rbs_value_typeObject

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.

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.



496
497
498
499
500
501
# File '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_factoriesObject

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.

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.



484
485
486
487
488
489
490
# File '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?Boolean

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.

Returns:

  • (Boolean)


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

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

#scalar_values_declObject

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.

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



516
517
518
# File '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

#union?Boolean

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.

Returns:

  • (Boolean)


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

def union? = true

#value_variantsObject

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.



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

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

#variant_factoriesObject

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 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).



475
476
477
478
479
# File '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