Class: QRPC::Protocol::ExceptionData
- Inherits:
-
JsonRpcObjects::Generic::Object
- Object
- JsonRpcObjects::Generic::Object
- QRPC::Protocol::ExceptionData
- Defined in:
- lib/qrpc/protocol/exception-data.rb
Overview
Exception data QRPC JSON-RPC object.
Constant Summary collapse
- VERSION =
Holds JSON-RPC version indication.
QRPC::Protocol::QrpcObject::VERSION
Instance Attribute Summary collapse
-
#backtrace ⇒ Array
Holds backtrace.
-
#dump ⇒ Class
Holds native dump.
-
#message ⇒ String
Holds exception message.
-
#name ⇒ Symbol
Holds exception name.
Class Method Summary collapse
-
.create(arg1, message = nil, opts = { }) ⇒ QRPC::Protocol::ExceptionData
Creates new QRPC JSON-RPC object.
Instance Method Summary collapse
-
#check! ⇒ Object
Checks correctness of the object data.
-
#initialize(data, mode = :encoded) ⇒ ExceptionData
constructor
Constructor.
-
#output ⇒ Hash
Renders data to output form.
Constructor Details
#initialize(data, mode = :encoded) ⇒ ExceptionData
Constructor.
115 116 117 118 |
# File 'lib/qrpc/protocol/exception-data.rb', line 115 def initialize(data, mode = :encoded) @__encoded = (mode == :encoded) super(data) end |
Instance Attribute Details
#backtrace ⇒ Array
Holds backtrace. See readme for structure details.
53 54 55 |
# File 'lib/qrpc/protocol/exception-data.rb', line 53 def backtrace @backtrace end |
#dump ⇒ Class
Holds native dump. See readme for structure details.
61 62 63 |
# File 'lib/qrpc/protocol/exception-data.rb', line 61 def dump @dump end |
#message ⇒ String
Holds exception message.
45 46 47 |
# File 'lib/qrpc/protocol/exception-data.rb', line 45 def @message end |
#name ⇒ Symbol
Holds exception name.
37 38 39 |
# File 'lib/qrpc/protocol/exception-data.rb', line 37 def name @name end |
Class Method Details
.create(exception, nil, opts = { }) ⇒ QRPC::Protocol::ExceptionData .create(name, message, opts = { }) ⇒ QRPC::Protocol::ExceptionData
Creates new QRPC JSON-RPC object.
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/qrpc/protocol/exception-data.rb', line 86 def self.create(arg1, = nil, opts = { }) if arg1.kind_of? ::Exception mode = :decoded data = { :name => arg1.class.name, :message => arg1., :backtrace => arg1.backtrace, :dump => { "format" => "ruby", "object" => arg1 } } else mode = :encoded data = { :name => arg1, :message => } end data.merge! opts return self::new(data, mode) end |
Instance Method Details
#check! ⇒ Object
Checks correctness of the object data.
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/qrpc/protocol/exception-data.rb', line 124 def check! self.normalize! if not @name.kind_of? Symbol raise Exception::new("Exception name is expected to be Symbol or convertable to symbol.") end if not @backtrace.nil? and not @backtrace.kind_of? Array raise Exception::new("Backtrace is expected to be an Array.") end if not @dump.nil? if @dump.object.nil? and @dump.raw.nil? raise Exception::new("Either object or RAW form of the dump must be set if dump is set.") elsif @dump.format.nil? or not @dump.format.kind_of? Symbol raise Exception::new("Dump format must be set and must be Symbol.") end end end |
#output ⇒ Hash
Renders data to output form.
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/qrpc/protocol/exception-data.rb', line 149 def output result = { :name => @name.to_s, :message => @message, } # Backtrace if @backtrace.kind_of? Array result[:backtrace] = @backtrace.map { |i| Base64.encode64(i) } end # Dump if not @dump.nil? result[:dump] = { :format => @dump.format, } if not dump.object.nil? raw = Base64.encode64(Marshal.dump(dump.object)) else raw = dump.raw end result[:dump][:raw] = raw end return result end |