Module: Selenium::WebDriver::BiDi::Serialization::Record::Serializable Private
| Relationships & Source Files | |
| Defined in: | rb/lib/selenium/webdriver/bidi/serialization/record.rb |
Class Method Summary
- .as_json(value) Internal use only
Instance Method Summary
-
#as_json
Internal use only
Omit UNSET fields; emit null only for nullable ones.
-
#merge_extensions!(payload)
private
Internal use only
Merge the passthrough extras onto the wire, erroring rather than letting an extra whose key is a declared field's wire key silently clobber that typed value; an extra is by definition a field the spec does not declare.
Class Method Details
.as_json(value)
[ GitHub ]# File 'rb/lib/selenium/webdriver/bidi/serialization/record.rb', line 357
def self.as_json(value) case value when Serializable then value.as_json when ::Array then value.map { |element| as_json(element) } when ::Hash then value.transform_values { |element| as_json(element) } else value end end
Instance Method Details
#as_json
Omit UNSET fields; emit null only for nullable ones.
# File 'rb/lib/selenium/webdriver/bidi/serialization/record.rb', line 367
def as_json(*) payload = {} self.class.fields.each do |f| value = public_send(f.name) next if UNSET.equal?(value) next if value.nil? && !f.nullable value = Serialization.to_wire(value, Protocol.const_get(f.enum)) if f.enum payload[f.wire_key] = Serializable.as_json(value) end merge_extensions!(payload) if self.class.extensible? && !extensions.empty? payload end
#merge_extensions!(payload) (private)
Merge the passthrough extras onto the wire, erroring rather than letting an extra whose key
is a declared field's wire key silently clobber that typed value; an extra is by definition
a field the spec does not declare. ::Selenium::WebDriver::Keys are stringified first so a symbol key (e.g. name:)
cannot slip past the guard and then reappear as a duplicate wire key once serialized. The
single gate every outbound path funnels through: new, with, and in-place mutation.
# File 'rb/lib/selenium/webdriver/bidi/serialization/record.rb', line 388
def merge_extensions!(payload) extras = extensions.transform_keys(&:to_s) collisions = extras.keys & self.class.fields.map(&:wire_key) unless collisions.empty? raise ::ArgumentError, "#{self.class.name} extensions shadow declared fields: #{collisions.join(', ')}" end payload.merge!(extras) end