Class: Gemstash::RackEnvRewriter::Context
- Inherits:
-
Object
- Object
- Gemstash::RackEnvRewriter::Context
- Extended by:
- Forwardable
- Includes:
- Logging
- Defined in:
- lib/gemstash/rack_env_rewriter.rb
Overview
Context containing the logic and the actual Rack environment.
Constant Summary
Constants included from Logging
Instance Method Summary collapse
- #captures ⇒ Object
-
#initialize(rewriter, rack_env) ⇒ Context
constructor
A new instance of Context.
- #matches? ⇒ Boolean
- #rewrite ⇒ Object
Methods included from Logging
#log, #log_error, logger, reset, setup_logger
Constructor Details
#initialize(rewriter, rack_env) ⇒ Context
Returns a new instance of Context.
26 27 28 29 |
# File 'lib/gemstash/rack_env_rewriter.rb', line 26 def initialize(rewriter, rack_env) @rewriter = rewriter @rack_env = rack_env end |
Instance Method Details
#captures ⇒ Object
50 51 52 53 54 55 56 57 58 |
# File 'lib/gemstash/rack_env_rewriter.rb', line 50 def captures @params ||= begin check_match @path_info_match.names.inject({}) do |result, name| result[name] = @path_info_match[name] result end end end |
#matches? ⇒ Boolean
31 32 33 |
# File 'lib/gemstash/rack_env_rewriter.rb', line 31 def matches? matches_request_uri? && matches_path_info? end |
#rewrite ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/gemstash/rack_env_rewriter.rb', line 35 def rewrite check_match log_start = "Rewriting '#{@rack_env["REQUEST_URI"]}'" new_request_uri = @rack_env["REQUEST_URI"].dup new_request_uri[@request_uri_match.begin(0)...@request_uri_match.end(0)] = "" new_path_info = @rack_env["PATH_INFO"].dup new_path_info[@path_info_match.begin(0)...@path_info_match.end(0)] = "" @rack_env["REQUEST_URI"] = new_request_uri @rack_env["PATH_INFO"] = new_path_info log.info "#{log_start} to '#{@rack_env["REQUEST_URI"]}'" end |