Class: Wee::Request

Inherits:
Rack::Request
  • Object
show all
Defined in:
lib/wee/request.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(env) ⇒ Request

Returns a new instance of Request.



15
16
17
18
19
20
# File 'lib/wee/request.rb', line 15

def initialize(env)
  super(env)
  @fields = self.params
  @session_id = @fields.delete("_s")
  @page_id = @fields.delete("_p")
end

Instance Attribute Details

#fieldsObject (readonly)

Returns the value of attribute fields.



11
12
13
# File 'lib/wee/request.rb', line 11

def fields
  @fields
end

#page_idObject

Returns the value of attribute page_id.



13
14
15
# File 'lib/wee/request.rb', line 13

def page_id
  @page_id
end

#session_idObject

Returns the value of attribute session_id.



12
13
14
# File 'lib/wee/request.rb', line 12

def session_id
  @session_id
end

Class Method Details

.new(env) ⇒ Object



7
8
9
# File 'lib/wee/request.rb', line 7

def self.new(env)
  env['wee.request'] ||= super 
end

Instance Method Details

#action?Boolean

Is this an action request?

Returns:

  • (Boolean)


23
24
25
# File 'lib/wee/request.rb', line 23

def action?
  not render?
end

#build_url(hash = {}) ⇒ Object

Raises:

  • (ArgumentError)


34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/wee/request.rb', line 34

def build_url(hash={})
  session_id = hash.has_key?(:session_id) ? hash[:session_id] : @session_id
  page_id = hash.has_key?(:page_id) ? hash[:page_id] : @page_id
  callback_id = hash[:callback_id]
  info = hash.has_key?(:info) ? hash[:info] : @info

  raise ArgumentError if session_id.nil? and not page_id.nil?
  raise ArgumentError if page_id.nil? and not callback_id.nil?

  q = {}
  q['_s'] = session_id if session_id
  q['_p'] = page_id if page_id
  q[callback_id] = nil if callback_id 

  path = script_name() + (info || path_info())
  path << "?" << Rack::Utils.build_query(q) unless q.empty? 

  return path
end

#render?Boolean

Is this a render request?

Returns:

  • (Boolean)


28
29
30
# File 'lib/wee/request.rb', line 28

def render?
  @fields.empty?
end