Class: MockServer::JsonRpcBody

Inherits:
Object
  • Object
show all
Defined in:
lib/mockserver/models.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(method_name:, params_schema: nil, not_body: false, optional: false) ⇒ JsonRpcBody

Returns a new instance of JsonRpcBody.



412
413
414
415
416
417
# File 'lib/mockserver/models.rb', line 412

def initialize(method_name:, params_schema: nil, not_body: false, optional: false)
  @method_name = method_name
  @params_schema = params_schema
  @not_body = not_body
  @optional = optional
end

Instance Attribute Details

#method_nameObject

Returns the value of attribute method_name.



410
411
412
# File 'lib/mockserver/models.rb', line 410

def method_name
  @method_name
end

#not_bodyObject

Returns the value of attribute not_body.



410
411
412
# File 'lib/mockserver/models.rb', line 410

def not_body
  @not_body
end

#optionalObject

Returns the value of attribute optional.



410
411
412
# File 'lib/mockserver/models.rb', line 410

def optional
  @optional
end

#params_schemaObject

Returns the value of attribute params_schema.



410
411
412
# File 'lib/mockserver/models.rb', line 410

def params_schema
  @params_schema
end

Class Method Details

.from_hash(data) ⇒ Object



427
428
429
430
431
432
433
434
435
436
# File 'lib/mockserver/models.rb', line 427

def self.from_hash(data)
  return nil if data.nil?

  new(
    method_name:   data['method'] || '',
    params_schema: data['paramsSchema'],
    not_body:      data.fetch('not', false),
    optional:      data.fetch('optional', false)
  )
end

Instance Method Details

#to_hObject



419
420
421
422
423
424
425
# File 'lib/mockserver/models.rb', line 419

def to_h
  result = { 'type' => 'JSON_RPC', 'method' => @method_name }
  result['paramsSchema'] = @params_schema if @params_schema
  result['not'] = true if @not_body
  result['optional'] = true if @optional
  result
end