Class: Selenium::WebDriver::BiDi::Serialization::Record Private
| Relationships & Source Files | |
| Namespace Children | |
|
Modules:
| |
|
Classes:
| |
| Super Chains via Extension / Inclusion / Inheritance | |
|
Class Chain:
self,
Data
|
|
|
Instance Chain:
self,
Data
|
|
| Inherits: |
Data
|
| Defined in: | rb/lib/selenium/webdriver/bidi/serialization/record.rb |
Overview
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'})
Class Method Summary
- .define(**spec) Internal use only
- .field(name, meta) private Internal use only
Class Method Details
.define(**spec)
[ GitHub ]# File 'rb/lib/selenium/webdriver/bidi/serialization/record.rb', line 34
def self.define(**spec) extensible = spec.delete(:extensible) || false fields = spec.map { |name, | field(name, ) } 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
.field(name, meta) (private)
[ GitHub ]# File 'rb/lib/selenium/webdriver/bidi/serialization/record.rb', line 57
def self.field(name, ) = {wire_key: } if .is_a?(::String) Field.new(name: name.to_sym, wire_key: .fetch(:wire_key, name.to_s), nullable: [:nullable] || false, ref: [:ref], list: [:list] || false, fixed: .fetch(:fixed, UNSET), enum: [:enum], required: .fetch(:required, true), primitive: [:primitive], scalar: [:scalar]) end