Class: MCollective::RPC::Reply

Inherits:
Object
  • Object
show all
Defined in:
lib/mcollective/rpc/reply.rb

Overview

Simple class to manage compliant replies to MCollective::RPC

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeReply

Returns a new instance of Reply.



7
8
9
10
11
# File 'lib/mcollective/rpc/reply.rb', line 7

def initialize
  @data = {}
  @statuscode = 0
  @statusmsg = "OK"
end

Instance Attribute Details

#dataObject

Returns the value of attribute data.



5
6
7
# File 'lib/mcollective/rpc/reply.rb', line 5

def data
  @data
end

#statuscodeObject

Returns the value of attribute statuscode.



5
6
7
# File 'lib/mcollective/rpc/reply.rb', line 5

def statuscode
  @statuscode
end

#statusmsgObject

Returns the value of attribute statusmsg.



5
6
7
# File 'lib/mcollective/rpc/reply.rb', line 5

def statusmsg
  @statusmsg
end

Instance Method Details

#[](key) ⇒ Object

Read from the data hash



48
49
50
# File 'lib/mcollective/rpc/reply.rb', line 48

def [](key)
  @data[key]
end

#[]=(key, val) ⇒ Object

Write to the data hash



43
44
45
# File 'lib/mcollective/rpc/reply.rb', line 43

def []=(key, val)
  @data[key] = val
end

#fail(msg, code = 1) ⇒ Object

Helper to fill in statusmsg and code on failure



14
15
16
17
# File 'lib/mcollective/rpc/reply.rb', line 14

def fail(msg, code=1)
  @statusmsg = msg
  @statuscode = code
end

#fail!(msg, code = 1) ⇒ Object

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



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/mcollective/rpc/reply.rb', line 20

def fail!(msg, code=1)
  @statusmsg = msg
  @statuscode = code

  case code
  when 1
    raise RPCAborted, msg

  when 2
    raise UnknownRPCAction, msg

  when 3
    raise MissingRPCData, msg

  when 4
    raise InvalidRPCData, msg

  else
    raise UnknownRPCError, msg
  end
end

#to_hashObject

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



54
55
56
57
58
# File 'lib/mcollective/rpc/reply.rb', line 54

def to_hash
  return {:statuscode => @statuscode,
    :statusmsg => @statusmsg,
    :data => @data}
end