Class: Rack::RPC::Endpoint::JSONRPC::Object

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/rpc/endpoint/jsonrpc.rb

Overview

Base class for JSON-RPC objects.

Direct Known Subclasses

Error, Notification, Response

Constant Summary collapse

OPTIONS =
{}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}, context = nil) ⇒ Object

Returns a new instance of Object.

Parameters:

  • options (Hash) (defaults to: {})
  • context (Object) (defaults to: nil)

    an optional context to associate with the object



127
128
129
130
131
132
133
# File 'lib/rack/rpc/endpoint/jsonrpc.rb', line 127

def initialize(options = {}, context = nil)
  options = self.class.const_get(:OPTIONS).merge(options)
  options.each do |k, v|
    instance_variable_set("@#{k}", v)
  end
  @context = context if context
end

Instance Attribute Details

#contextObject (readonly)

An arbitrary context associated with the object.

Returns:



121
122
123
# File 'lib/rack/rpc/endpoint/jsonrpc.rb', line 121

def context
  @context
end

Class Method Details

.parse(input) ⇒ Object

Parameters:

  • input (String)

Returns:



113
114
115
# File 'lib/rack/rpc/endpoint/jsonrpc.rb', line 113

def self.parse(input)
  self.new(JSON.parse(input))
end

Instance Method Details

#to_jsonString

Returns:

  • (String)


137
138
139
# File 'lib/rack/rpc/endpoint/jsonrpc.rb', line 137

def to_json
  to_hash.delete_if { |k, v| v.nil? }.to_json
end