Class: Tzispa::Http::Context
- Extended by:
- Forwardable
- Includes:
- Tzispa::Helpers::Response, Tzispa::Helpers::Session
- Defined in:
- lib/tzispa/http/context.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#request ⇒ Object
readonly
Returns the value of attribute request.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Attributes inherited from Context
Instance Method Summary collapse
- #app_canonical_url(app_name, path_id, params = {}) ⇒ Object
- #app_path(app_name, path_id, params = {}) ⇒ Object
- #canonical_root ⇒ Object
- #canonical_url(path_id, params = {}) ⇒ Object
- #error_log(ex, status = nil) ⇒ Object
- #info_log(ex, status = nil) ⇒ Object
-
#initialize(app, env) ⇒ Context
constructor
A new instance of Context.
- #path(path_id, params = {}) ⇒ Object
- #request_method ⇒ Object
- #router_params ⇒ Object
Constructor Details
Instance Attribute Details
#request ⇒ Object (readonly)
Returns the value of attribute request.
19 20 21 |
# File 'lib/tzispa/http/context.rb', line 19 def request @request end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
19 20 21 |
# File 'lib/tzispa/http/context.rb', line 19 def response @response end |
Instance Method Details
#app_canonical_url(app_name, path_id, params = {}) ⇒ Object
63 64 65 |
# File 'lib/tzispa/http/context.rb', line 63 def app_canonical_url(app_name, path_id, params = {}) "#{canonical_root}#{app_path(app_name, path_id, params)}" end |
#app_path(app_name, path_id, params = {}) ⇒ Object
46 47 48 |
# File 'lib/tzispa/http/context.rb', line 46 def app_path(app_name, path_id, params = {}) app[app_name].routes.path path_id, params end |
#canonical_root ⇒ Object
50 51 52 53 54 55 56 57 |
# File 'lib/tzispa/http/context.rb', line 50 def canonical_root @canonical_root ||= begin http_proto = Tzispa::Environment.instance.ssl? ? 'https://' : 'http://' http_host = Tzispa::Environment.instance.host http_port = Tzispa::Environment.instance.uri_port "#{http_proto}#{http_host}#{http_port}" end end |
#canonical_url(path_id, params = {}) ⇒ Object
59 60 61 |
# File 'lib/tzispa/http/context.rb', line 59 def canonical_url(path_id, params = {}) "#{canonical_root}#{path(path_id, params)}" end |
#error_log(ex, status = nil) ⇒ Object
67 68 69 |
# File 'lib/tzispa/http/context.rb', line 67 def error_log(ex, status = nil) logger.error "E [#{request.ip}] #{request.request_method} #{request.fullpath} #{status || response.status}\n#{ex.backtrace.first}: #{ex.} (#{ex.class})\n#{ex.backtrace.drop(1).map { |s| "\t#{s}" }.join("\n") }" end |
#info_log(ex, status = nil) ⇒ Object
71 72 73 |
# File 'lib/tzispa/http/context.rb', line 71 def info_log(ex, status = nil) logger.info "I [#{request.ip}] #{request.request_method} #{request.fullpath} #{status || response.status}\n#{ex.backtrace.first}: #{ex.} (#{ex.class})\n#{ex.backtrace.drop(1).map { |s| "\t#{s}" }.join("\n") }" end |
#path(path_id, params = {}) ⇒ Object
42 43 44 |
# File 'lib/tzispa/http/context.rb', line 42 def path(path_id, params = {}) app.routes.path path_id, params end |
#request_method ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/tzispa/http/context.rb', line 29 def request_method if request.request_method == 'POST' && request['_method'] env[Request::REQUEST_METHOD] = request['_method'] request['_method'] else request.request_method end end |
#router_params ⇒ Object
38 39 40 |
# File 'lib/tzispa/http/context.rb', line 38 def router_params env['router.params'] || {} end |