Module: Bidi2pdf::Bidi::Commands::Base
- Included in:
- AddIntercept, BrowserClose, BrowserCreateUserContext, BrowserRemoveUserContext, BrowsingContextClose, BrowsingContextNavigate, BrowsingContextPrint, CancelAuth, CdpGetSession, CreateWindow, GetUserContexts, NetworkContinue, PagePrint, ProvideCredentials, ScriptEvaluate, SessionEnd, SessionStatus, SessionSubscribe, SetTabCookie, SetUsercontextCookie
- Defined in:
- lib/bidi2pdf/bidi/commands/base.rb
Overview
Base module for defining WebSocket commands in the Bidi2pdf library. This module provides common functionality for creating, comparing, and inspecting WebSocket command payloads.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
Compares the current command with another command for equality.
-
#as_payload(id) ⇒ Hash
Constructs the payload for the WebSocket command.
-
#eql?(other) ⇒ Boolean
Checks if the current command is hash-equal to another command.
-
#hash ⇒ Integer
Computes the hash value for the command.
-
#inspect ⇒ String
Returns a string representation of the command, with sensitive fields redacted.
-
#method_name ⇒ Object
Abstract method that must be implemented in subclasses to define the WebSocket command method name.
-
#params ⇒ Hash
Returns the parameters for the WebSocket command.
Instance Method Details
#==(other) ⇒ Boolean
Compares the current command with another command for equality.
rubocop: disable Metrics/AbcSize
38 39 40 41 42 43 44 45 46 |
# File 'lib/bidi2pdf/bidi/commands/base.rb', line 38 def ==(other) return false unless other.respond_to?(:method_name) && other.respond_to?(:params) return false unless method_name == other.method_name return false unless params.keys.sort == other.params.keys.sort params.all? { |key, value| other.params.key?(key) && value == other.params[key] } end |
#as_payload(id) ⇒ Hash
Constructs the payload for the WebSocket command.
25 26 27 28 29 30 31 |
# File 'lib/bidi2pdf/bidi/commands/base.rb', line 25 def as_payload(id) { id: id, method: method_name, params: params } end |
#eql?(other) ⇒ Boolean
Checks if the current command is hash-equal to another command.
54 55 56 57 58 |
# File 'lib/bidi2pdf/bidi/commands/base.rb', line 54 def eql?(other) return false unless other.is_a?(Bidi2pdf::Bidi::Commands::Base) self == other end |
#hash ⇒ Integer
Computes the hash value for the command.
63 64 65 |
# File 'lib/bidi2pdf/bidi/commands/base.rb', line 63 def hash [method_name, params].hash end |
#inspect ⇒ String
Returns a string representation of the command, with sensitive fields redacted.
70 71 72 73 74 |
# File 'lib/bidi2pdf/bidi/commands/base.rb', line 70 def inspect attributes = redact_sensitive_fields({ method_name: method_name, params: params }) "#<#{self.class}:#{object_id} #{attributes}>" end |
#method_name ⇒ Object
Abstract method that must be implemented in subclasses to define the WebSocket command method name.
14 |
# File 'lib/bidi2pdf/bidi/commands/base.rb', line 14 def method_name = raise(NotImplementedError, "method_name must be implemented in subclass") |
#params ⇒ Hash
Returns the parameters for the WebSocket command.
19 |
# File 'lib/bidi2pdf/bidi/commands/base.rb', line 19 def params = {} |