Class: JSON_RPC::Notification
- Inherits:
-
Data
- Object
- Data
- JSON_RPC::Notification
- Defined in:
- lib/json_rpc/notification.rb
Overview
Represents a JSON-RPC notification.
Instance Attribute Summary collapse
-
#method ⇒ Object
readonly
Returns the value of attribute method.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
Class Method Summary collapse
Instance Method Summary collapse
- #as_json ⇒ Object
-
#initialize(method:, params: nil) ⇒ Notification
constructor
Initializes a new Notification.
-
#to_h ⇒ Hash
Returns a hash representation of the notification, ready for JSON serialization.
Constructor Details
#initialize(method:, params: nil) ⇒ Notification
Initializes a new Notification.
10 11 12 13 |
# File 'lib/json_rpc/notification.rb', line 10 def initialize(method:, params: nil) # Basic validation could be added here if needed, e.g., method is a non-empty string. super end |
Instance Attribute Details
#method ⇒ Object (readonly)
Returns the value of attribute method
5 6 7 |
# File 'lib/json_rpc/notification.rb', line 5 def method @method end |
#params ⇒ Object (readonly)
Returns the value of attribute params
5 6 7 |
# File 'lib/json_rpc/notification.rb', line 5 def params @params end |
Class Method Details
.from_h(h) ⇒ Object
15 16 17 |
# File 'lib/json_rpc/notification.rb', line 15 def self.from_h(h) new(method: h["method"], params: h["params"]) end |
Instance Method Details
#as_json ⇒ Object
32 |
# File 'lib/json_rpc/notification.rb', line 32 def as_json(*) = to_h |
#to_h ⇒ Hash
Returns a hash representation of the notification, ready for JSON serialization.
22 23 24 25 26 27 28 29 30 |
# File 'lib/json_rpc/notification.rb', line 22 def to_h hash = { "jsonrpc" => "2.0", method: method } # Include params only if it's not nil, as per JSON-RPC spec hash[:params] = params unless params.nil? hash end |