Class: Wee::Request

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

Overview

Represents a request.

NOTE that if there are fields named “xxx” and “xxx.yyy”, the value of fields is a Hash => val of “xxx”, ‘yyy’ => val of ‘xxx.yyy’. This is for the image-button to work correctly.

Direct Known Subclasses

PagelessRequest

Constant Summary collapse

DELIM =
'/___/'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app_path, path, headers, fields, cookies) ⇒ Request

Returns a new instance of Request.

Raises:

  • (ArgumentError)


17
18
19
20
21
22
# File 'lib/wee/request.rb', line 17

def initialize(app_path, path, headers, fields, cookies)
  raise ArgumentError if app_path[-1] == ?/
  @app_path, @path, @headers, @cookies = app_path, path, headers, cookies
  parse_fields(fields)
  parse_path
end

Instance Attribute Details

#cookiesObject (readonly)

Returns the value of attribute cookies.



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

def cookies
  @cookies
end

#fieldsObject (readonly)

Returns the value of attribute fields.



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

def fields
  @fields
end

#infoObject

The part of the URL that is user-defineable



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

def info
  @info
end

#page_idObject (readonly)

Returns the value of attribute page_id.



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

def page_id
  @page_id
end

#request_handler_idObject

Returns the value of attribute request_handler_id.



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

def request_handler_id
  @request_handler_id
end

Instance Method Details

#action?Boolean

Is this an action request?

Returns:

  • (Boolean)


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

def action?
  not render?
end

#application_pathObject



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

def application_path
  @app_path
end

#build_url(hash = {}) ⇒ Object

Raises:

  • (ArgumentError)


38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/wee/request.rb', line 38

def build_url(hash={})
  default = {
    :request_handler_id => self.request_handler_id,
    :page_id => self.page_id,
    :info => self.info
  }
  hash = default.update(hash)

  request_handler_id = hash[:request_handler_id]
  page_id = hash[:page_id]
  callback_id = hash[:callback_id]
  info = hash[:info]

  raise ArgumentError if request_handler_id.nil? and not page_id.nil?
  if not pageless?
    raise ArgumentError if page_id.nil? and not callback_id.nil?
  end

  # build request path, e.g. /___/req-id/page-id
  req_path = make_request_path(request_handler_id, page_id)

  # build the whole url
  url = ""
  url << @app_path

  raise if url[-1] == ?/  # sanity check

  if info
    url << '/'
    url << info
  end
  url << req_path 

  url << '/' if info.nil? and req_path.empty? 

  url << ('?' + callback_id) if callback_id

  return url
end

#render?Boolean

Is this a render request?

Returns:

  • (Boolean)


34
35
36
# File 'lib/wee/request.rb', line 34

def render?
  self.fields.empty?
end