Class: Hyde::Request
- Inherits:
-
Object
- Object
- Hyde::Request
- Defined in:
- lib/hyde/request.rb
Overview
Request wrapper for Rack protocol
Instance Attribute Summary collapse
-
#filepath ⇒ Object
Returns the value of attribute filepath.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#param ⇒ Object
readonly
Returns the value of attribute param.
-
#path ⇒ Object
Returns the value of attribute path.
-
#path_info ⇒ Object
readonly
Returns the value of attribute path_info.
-
#postprocessors ⇒ Object
readonly
Returns the value of attribute postprocessors.
-
#query ⇒ Object
readonly
Returns the value of attribute query.
-
#request_method ⇒ Object
readonly
Returns the value of attribute request_method.
-
#script_name ⇒ Object
readonly
Returns the value of attribute script_name.
-
#server_name ⇒ Object
readonly
Returns the value of attribute server_name.
-
#server_port ⇒ Object
readonly
Returns the value of attribute server_port.
-
#server_protocol ⇒ Object
readonly
Returns the value of attribute server_protocol.
-
#splat ⇒ Object
readonly
Returns the value of attribute splat.
Instance Method Summary collapse
-
#body ⇒ nil, String
Returns request body (if POST data exists).
-
#initialize(env) ⇒ Request
constructor
A new instance of Request.
-
#input ⇒ IO
Returns raw Rack input object.
-
#pop_state ⇒ Object
Load last navigation state (path, splat, param) from state stack.
-
#push_state ⇒ Object
Push current navigation state (path, splat, param) onto state stack.
-
#run_postprocessors(response) ⇒ Object
Run postprocessors.
Constructor Details
#initialize(env) ⇒ Request
Returns a new instance of Request.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/hyde/request.rb', line 10 def initialize(env) # Should not be used under regular circumstances or depended upon. @_original_env = env # Rack environment variable bindings. Should be public and frozen. init_request_params(env) # Query parsing @query = Hyde::Util::Query.new(@query_string) # Pattern matching parameters. Public, readable, unfrozen. @param = {} @splat = [] # Traversal route. Public and writable. @path = URI.decode_www_form_component(env["PATH_INFO"].dup) # File serving path. Public and writable. @filepath = "/" # Encapsulates all rack variables. Should not be public. @rack = init_rack_vars(env) # Internal navigation states. Private. @states = [] # Postprocessors for current request @postprocessors = [] end |
Instance Attribute Details
#filepath ⇒ Object
Returns the value of attribute filepath.
65 66 67 |
# File 'lib/hyde/request.rb', line 65 def filepath @filepath end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
62 63 64 |
# File 'lib/hyde/request.rb', line 62 def headers @headers end |
#param ⇒ Object (readonly)
Returns the value of attribute param.
62 63 64 |
# File 'lib/hyde/request.rb', line 62 def param @param end |
#path ⇒ Object
Returns the value of attribute path.
65 66 67 |
# File 'lib/hyde/request.rb', line 65 def path @path end |
#path_info ⇒ Object (readonly)
Returns the value of attribute path_info.
62 63 64 |
# File 'lib/hyde/request.rb', line 62 def path_info @path_info end |
#postprocessors ⇒ Object (readonly)
Returns the value of attribute postprocessors.
62 63 64 |
# File 'lib/hyde/request.rb', line 62 def postprocessors @postprocessors end |
#query ⇒ Object (readonly)
Returns the value of attribute query.
62 63 64 |
# File 'lib/hyde/request.rb', line 62 def query @query end |
#request_method ⇒ Object (readonly)
Returns the value of attribute request_method.
62 63 64 |
# File 'lib/hyde/request.rb', line 62 def request_method @request_method end |
#script_name ⇒ Object (readonly)
Returns the value of attribute script_name.
62 63 64 |
# File 'lib/hyde/request.rb', line 62 def script_name @script_name end |
#server_name ⇒ Object (readonly)
Returns the value of attribute server_name.
62 63 64 |
# File 'lib/hyde/request.rb', line 62 def server_name @server_name end |
#server_port ⇒ Object (readonly)
Returns the value of attribute server_port.
62 63 64 |
# File 'lib/hyde/request.rb', line 62 def server_port @server_port end |
#server_protocol ⇒ Object (readonly)
Returns the value of attribute server_protocol.
62 63 64 |
# File 'lib/hyde/request.rb', line 62 def server_protocol @server_protocol end |
#splat ⇒ Object (readonly)
Returns the value of attribute splat.
62 63 64 |
# File 'lib/hyde/request.rb', line 62 def splat @splat end |
Instance Method Details
#body ⇒ nil, String
Returns request body (if POST data exists)
42 43 44 |
# File 'lib/hyde/request.rb', line 42 def body @body ||= @rack.input&.read end |
#input ⇒ IO
Returns raw Rack input object
48 49 50 |
# File 'lib/hyde/request.rb', line 48 def input @rack.input end |
#pop_state ⇒ Object
Load last navigation state (path, splat, param) from state stack
58 59 60 |
# File 'lib/hyde/request.rb', line 58 def pop_state @path, @param, @splat, @filepath = @states.pop end |
#push_state ⇒ Object
Push current navigation state (path, splat, param) onto state stack
53 54 55 |
# File 'lib/hyde/request.rb', line 53 def push_state @states.push([@path, @param.dup, @splat.dup, @filepath.dup]) end |
#run_postprocessors(response) ⇒ Object
Run postprocessors
34 35 36 37 38 |
# File 'lib/hyde/request.rb', line 34 def run_postprocessors(response) @postprocessors.each do |postproc| postproc.call(self, response) end end |