Class: XResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/rails-extjs-direct/xresponse.rb

Overview

XResponse A standard response class suitable for Ext.Direct AJAX responses.

Author:

  • Chris Scott

Direct Known Subclasses

XExceptionResponse

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(req) ⇒ XResponse

Returns a new instance of XResponse.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/rails-extjs-direct/xresponse.rb', line 10

def initialize(req)
    if req.kind_of?(XRequest)
      @tid    = req.tid
      @type   = req.type
    else
      req.kind_of?(Hash)
      @tid = req["tid"]
      @type = req["type"]
    end
    @status = false
    @message = ''
    @result = []
    @errors = []
end

Instance Attribute Details

#errorsObject

Returns the value of attribute errors.



7
8
9
# File 'lib/rails-extjs-direct/xresponse.rb', line 7

def errors
  @errors
end

#messageObject

Returns the value of attribute message.



7
8
9
# File 'lib/rails-extjs-direct/xresponse.rb', line 7

def message
  @message
end

#resultObject

Returns the value of attribute result.



7
8
9
# File 'lib/rails-extjs-direct/xresponse.rb', line 7

def result
  @result
end

#statusObject

Returns the value of attribute status.



7
8
9
# File 'lib/rails-extjs-direct/xresponse.rb', line 7

def status
  @status
end

#successObject

Returns the value of attribute success.



7
8
9
# File 'lib/rails-extjs-direct/xresponse.rb', line 7

def success
  @success
end

#tidObject (readonly)

Returns the value of attribute tid.



8
9
10
# File 'lib/rails-extjs-direct/xresponse.rb', line 8

def tid
  @tid
end

#typeObject

Returns the value of attribute type.



7
8
9
# File 'lib/rails-extjs-direct/xresponse.rb', line 7

def type
  @type
end

Instance Method Details

#to_hObject



25
26
27
# File 'lib/rails-extjs-direct/xresponse.rb', line 25

def to_h
    {:tid => @tid, :status => @status, :type => @type, :message => @message, :result => @result, :errors => @errors}
end

#to_json(*p) ⇒ Object



29
30
31
# File 'lib/rails-extjs-direct/xresponse.rb', line 29

def to_json(*p)
    self.to_h.to_json
end