Class: Selenium::WebDriver::BiDi::Serialization::Record Private

Inherits:
Data
  • Object
show all
Defined in:
lib/selenium/webdriver/bidi/serialization/record.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.

Immutable value type for the generated protocol classes. Record.define(spec) bakes each field's wire facts and returns a ::Data subclass with serialization.

Cookie = Record.define(name: 'name', value: {wire_key: 'value', ref: 'Network::BytesValue'})

Defined Under Namespace

Modules: Deserializer, Serializable Classes: Field

Class Method Summary collapse

Class Method Details

.define(**spec) ⇒ 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.



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/selenium/webdriver/bidi/serialization/record.rb', line 34

def self.define(**spec)
  extensible = spec.delete(:extensible) || false
  fields = spec.map { |name, meta| field(name, meta) }
  names = fields.map(&:name)
  names << :extensions if extensible

  klass = super(*names)
  fields.freeze
  # Singleton methods are inherited by `X = Record.define(…)`; ivars would not.
  klass.define_singleton_method(:fields) { fields }
  klass.define_singleton_method(:extensible?) { extensible }
  klass.include(Serializable)
  # Capture ::Data's generated +new+, then prepend (not include) Deserializer so
  # its +new+ overrides it — outbound +new+ adds validation, while inbound
  # +from_json+ builds directly via the captured constructor. Bound to +self+ so a
  # subclass builds itself, not the base.
  data_new = klass.singleton_class.instance_method(:new)
  klass.singleton_class.prepend(Deserializer)
  klass.define_singleton_method(:construct) { |**attributes| data_new.bind_call(self, **attributes) }
  klass.singleton_class.send(:private, :construct)
  klass
end