Class MCollective::RPC::Reply
In: lib/mcollective/rpc/reply.rb
Parent: Object

Simple class to manage compliant replies to MCollective::RPC

Methods

[]   []=   fail   fail!   new   to_hash  

Attributes

data  [RW] 
statuscode  [RW] 
statusmsg  [RW] 

Public Class methods

[Source]

    # File lib/mcollective/rpc/reply.rb, line 7
 7:       def initialize
 8:         @data = {}
 9:         @statuscode = 0
10:         @statusmsg = "OK"
11:       end

Public Instance methods

Read from the data hash

[Source]

    # File lib/mcollective/rpc/reply.rb, line 48
48:       def [](key)
49:         @data[key]
50:       end

Write to the data hash

[Source]

    # File lib/mcollective/rpc/reply.rb, line 43
43:       def []=(key, val)
44:         @data[key] = val
45:       end

Helper to fill in statusmsg and code on failure

[Source]

    # File lib/mcollective/rpc/reply.rb, line 14
14:       def fail(msg, code=1)
15:         @statusmsg = msg
16:         @statuscode = code
17:       end

Helper that fills in statusmsg and code but also raises an appropriate error

[Source]

    # File lib/mcollective/rpc/reply.rb, line 20
20:       def fail!(msg, code=1)
21:         @statusmsg = msg
22:         @statuscode = code
23: 
24:         case code
25:         when 1
26:           raise RPCAborted, msg
27: 
28:         when 2
29:           raise UnknownRPCAction, msg
30: 
31:         when 3
32:           raise MissingRPCData, msg
33: 
34:         when 4
35:           raise InvalidRPCData, msg
36: 
37:         else
38:           raise UnknownRPCError, msg
39:         end
40:       end

Returns a compliant Hash of the reply that should be sent over the middleware

[Source]

    # File lib/mcollective/rpc/reply.rb, line 54
54:       def to_hash
55:         return {:statuscode => @statuscode,
56:           :statusmsg => @statusmsg,
57:           :data => @data}
58:       end

[Validate]