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

OPTIONS =
{}

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Object) initialize(options = {}, context = nil)

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

- (Object) context (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

+ (Object) parse(input)

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

- (String) to_json

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