class RackReverseProxy::Rule::Candidate

Candidate represents a request being matched

Attributes

env[R]
has_custom_url[R]
matches[R]
path[R]
rule[R]
url[R]

Public Class Methods

new(rule, has_custom_url, path, env, matches) click to toggle source
# File lib/rack_reverse_proxy/rule.rb, line 66
def initialize(rule, has_custom_url, path, env, matches)
  @rule = rule
  @env = env
  @path = path
  @has_custom_url = has_custom_url
  @matches = matches

  @url = evaluate(matches.custom_url)
end

Public Instance Methods

build_uri() click to toggle source
# File lib/rack_reverse_proxy/rule.rb, line 76
def build_uri
  return nil unless url
  raw_uri
end
transform(response, request_uri) click to toggle source
# File lib/rack_reverse_proxy/rule.rb, line 81
def transform(response, request_uri)
  matches.transform(response, request_uri)
end

Private Instance Methods

evaluate(url) click to toggle source
# File lib/rack_reverse_proxy/rule.rb, line 103
def evaluate(url)
  return unless url
  return url.call(env) if lazy?(url)
  url.clone
end
just_uri() click to toggle source
# File lib/rack_reverse_proxy/rule.rb, line 95
def just_uri
  URI.parse(url)
end
lazy?(url) click to toggle source
# File lib/rack_reverse_proxy/rule.rb, line 109
def lazy?(url)
  url.respond_to?(:call)
end
raw_uri() click to toggle source
# File lib/rack_reverse_proxy/rule.rb, line 89
def raw_uri
  return substitute_matches if with_substitutions?
  return just_uri if has_custom_url
  uri_with_path
end
substitute_matches() click to toggle source
# File lib/rack_reverse_proxy/rule.rb, line 117
def substitute_matches
  URI(matches.substitute(url))
end
uri_with_path() click to toggle source
# File lib/rack_reverse_proxy/rule.rb, line 99
def uri_with_path
  URI.join(url, path)
end
with_substitutions?() click to toggle source
# File lib/rack_reverse_proxy/rule.rb, line 113
def with_substitutions?
  url =~ /\$\d/
end