Class: XRequest

Inherits:
Object
  • Object
show all
Defined in:
lib/merb-extjs-direct/xrequest.rb

Overview

XRequest A standard response class suitable for Ext.Direct requests.

Author:

  • Chris Scott

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ XRequest

Returns a new instance of XRequest.



9
10
11
12
13
14
15
16
17
# File 'lib/merb-extjs-direct/xrequest.rb', line 9

def initialize(params)
    # TODO: simply setting @id, @params
    @id         = (params["id"].to_i > 0) ? params["id"].to_i : (params["data"].kind_of?(Array) && (params["data"].first.kind_of?(Integer) || params["data"].first.nil?)) ? params["data"].shift: nil
    @tid        = params["tid"]
    @type       = params["type"]
    @params     = (params["data"].kind_of?(Array) && params["data"].length == 1 && params["data"].first.kind_of?(Hash)) ? params["data"].first : params["data"] || []
    @controller = params["xcontroller"]
    @action     = params["xaction"]
end

Instance Attribute Details

#actionObject (readonly)

Returns the value of attribute action.



7
8
9
# File 'lib/merb-extjs-direct/xrequest.rb', line 7

def action
  @action
end

#controllerObject (readonly)

Returns the value of attribute controller.



7
8
9
# File 'lib/merb-extjs-direct/xrequest.rb', line 7

def controller
  @controller
end

#idObject (readonly)

Returns the value of attribute id.



7
8
9
# File 'lib/merb-extjs-direct/xrequest.rb', line 7

def id
  @id
end

#paramsObject (readonly)

Returns the value of attribute params.



7
8
9
# File 'lib/merb-extjs-direct/xrequest.rb', line 7

def params
  @params
end

#tidObject (readonly)

Returns the value of attribute tid.



7
8
9
# File 'lib/merb-extjs-direct/xrequest.rb', line 7

def tid
  @tid
end

#typeObject (readonly)

Returns the value of attribute type.



7
8
9
# File 'lib/merb-extjs-direct/xrequest.rb', line 7

def type
  @type
end

Instance Method Details

#arg(index) ⇒ Object

arg return a request argument at index. can be used to access either [] or {}

Parameters:

  • index (String/Integer)


25
26
27
28
29
30
# File 'lib/merb-extjs-direct/xrequest.rb', line 25

def arg(index)
    if params[index].nil?
        raise XException.new("Attempt to access unknown request argument '#{index.to_s}' on transaction #{@tid}")
    end
    @params[index]
end