Class: Rack::RPC::Endpoint::JSONRPC::Object
- Inherits:
-
Object
- Object
- Rack::RPC::Endpoint::JSONRPC::Object
- Defined in:
- lib/rack/rpc/endpoint/jsonrpc.rb
Overview
Base class for JSON-RPC objects.
Direct Known Subclasses
Constant Summary collapse
- OPTIONS =
{}
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
An arbitrary context associated with the object.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(options = {}, context = nil) ⇒ Object
constructor
A new instance of Object.
- #to_json ⇒ String
Constructor Details
#initialize(options = {}, context = nil) ⇒ Object
Returns a new instance of Object.
127 128 129 130 131 132 133 |
# File 'lib/rack/rpc/endpoint/jsonrpc.rb', line 127 def initialize( = {}, context = nil) = self.class.const_get(:OPTIONS).merge() .each do |k, v| instance_variable_set("@#{k}", v) end @context = context if context end |
Instance Attribute Details
#context ⇒ Object (readonly)
An arbitrary context associated with the object.
121 122 123 |
# File 'lib/rack/rpc/endpoint/jsonrpc.rb', line 121 def context @context end |
Class Method Details
.parse(input) ⇒ Object
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_json ⇒ 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 |