Class: Protocol::WebSocket::Coder::JSON

Inherits:
Object
  • Object
show all
Defined in:
lib/protocol/websocket/coder/json.rb

Overview

A JSON coder that uses the standard JSON library.

Constant Summary collapse

DEFAULT =

The default JSON coder. This coder will symbolize names.

new(symbolize_names: true)

Instance Method Summary collapse

Constructor Details

#initialize(**options) ⇒ JSON

Initialize a new JSON coder.



15
16
17
# File 'lib/protocol/websocket/coder/json.rb', line 15

def initialize(**options)
	@options = options
end

Instance Method Details

#generate(object) ⇒ Object

Generate a JSON buffer from an object.



25
26
27
# File 'lib/protocol/websocket/coder/json.rb', line 25

def generate(object)
	::JSON.generate(object, **@options)
end

#parse(buffer) ⇒ Object

Parse a JSON buffer into an object.



20
21
22
# File 'lib/protocol/websocket/coder/json.rb', line 20

def parse(buffer)
	::JSON.parse(buffer, **@options)
end