Class: Gemstash::RackEnvRewriter::Context

Inherits:
Object
  • Object
show all
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

Logging::LEVELS

Instance Method Summary collapse

Methods included from Logging

#log, #log_error, logger, reset, setup_logger

Constructor Details

#initialize(rewriter, rack_env) ⇒ Context

Returns a new instance of Context.



24
25
26
27
# File 'lib/gemstash/rack_env_rewriter.rb', line 24

def initialize(rewriter, rack_env)
  @rewriter = rewriter
  @rack_env = rack_env
end

Instance Method Details

#capturesObject



41
42
43
44
45
46
47
48
49
# File 'lib/gemstash/rack_env_rewriter.rb', line 41

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

Returns:

  • (Boolean)


29
30
31
# File 'lib/gemstash/rack_env_rewriter.rb', line 29

def matches?
  matches_request_uri? && matches_path_info?
end

#rewriteObject



33
34
35
36
37
38
39
# File 'lib/gemstash/rack_env_rewriter.rb', line 33

def rewrite
  check_match
  log_start = "Rewriting '#{@rack_env["REQUEST_URI"]}'"
  @rack_env["REQUEST_URI"][@request_uri_match.begin(0)...@request_uri_match.end(0)] = ""
  @rack_env["PATH_INFO"][@path_info_match.begin(0)...@path_info_match.end(0)] = ""
  log.info "#{log_start} to '#{@rack_env["REQUEST_URI"]}'"
end