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

Returns a new instance of JSON.



13
14
15
# File 'lib/protocol/websocket/coder/json.rb', line 13

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

Instance Method Details

#generate(object) ⇒ Object

Generate a JSON buffer from an object.



23
24
25
# File 'lib/protocol/websocket/coder/json.rb', line 23

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

#parse(buffer) ⇒ Object

Parse a JSON buffer into an object.



18
19
20
# File 'lib/protocol/websocket/coder/json.rb', line 18

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