Class Dsadmin::Response
In: lib/dsadmin/response.rb
Parent: Object

Response encapsulation for communication with admind

Methods

data=   from_yaml   new   status=   to_yaml  

Included Modules

ValueChecker

Attributes

data  [R] 
status  [R] 

Public Class methods

Create a new Response and deserialize it from the given YAML Raises an ArgumentError if the data is invalid

[Source]

    # File lib/dsadmin/response.rb, line 48
48:     def self.from_yaml(string_or_io)
49:       hash = YAML.load(string_or_io)
50:       raise ArgumentError.new("Unrecognized data format") unless(hash.kind_of?(Hash))
51: 
52:       status = hash['status']
53:       raise ArgumentError.new("Invalid status") unless(status.kind_of?(String))
54:       
55:       req = Response.new(status.to_sym)
56:       req.data = hash['data']
57:       
58:       req
59:     end

[Source]

    # File lib/dsadmin/response.rb, line 63
63:     def initialize(status, data = nil)
64:       self.status = status
65:       self.data = data
66:     end

Public Instance methods

[Source]

    # File lib/dsadmin/response.rb, line 31
31:     def data=(value)
32:       checkKindOf(Hash, value) unless value.nil?
33:       @data = value
34:     end

[Source]

    # File lib/dsadmin/response.rb, line 26
26:     def status=(value)
27:       requireKindOf(Symbol, value)
28:       @status = value
29:     end

Serialize the object to YAML

[Source]

    # File lib/dsadmin/response.rb, line 38
38:     def to_yaml
39:       hash = Hash.new
40:       hash['status'] = status.to_s
41:       hash['data']   = data unless data.nil?
42:       
43:       hash.to_yaml
44:     end

[Validate]