class RackReverseProxy::Rule

Rule understands which urls need to be proxied

Attributes

has_custom_url[R]
options[R]

FIXME: It needs to be hidden

spec[R]
url[R]

Public Class Methods

new(spec, url = nil, options = {}) click to toggle source
# File lib/rack_reverse_proxy/rule.rb, line 7
def initialize(spec, url = nil, options = {})
  @has_custom_url = url.nil?
  @url = url
  @options = options
  @spec = build_matcher(spec)
end

Public Instance Methods

get_uri(path, env, *args) click to toggle source
# File lib/rack_reverse_proxy/rule.rb, line 18
def get_uri(path, env, *args)
  Candidate.new(
    self,
    has_custom_url,
    path,
    env,
    matches(path, *args)
  ).build_uri
end
proxy?(path, *args) click to toggle source
# File lib/rack_reverse_proxy/rule.rb, line 14
def proxy?(path, *args)
  matches(path, *args).any?
end
to_s() click to toggle source
# File lib/rack_reverse_proxy/rule.rb, line 38
def to_s
  %("#{spec}" => "#{url}")
end
transform(path, env, response, request_uri, *args) click to toggle source
# File lib/rack_reverse_proxy/rule.rb, line 28
def transform(path, env, response, request_uri, *args)
  Candidate.new(
    self,
    has_custom_url,
    path,
    env,
    matches(path, *args)
  ).transform(response, request_uri)
end

Private Instance Methods

build_matcher(spec) click to toggle source
# File lib/rack_reverse_proxy/rule.rb, line 57
def build_matcher(spec)
  return /^#{spec}/ if spec.is_a?(String)
  return spec if spec.respond_to?(:match)
  return spec if spec.respond_to?(:call)
  raise ArgumentError, "Invalid Rule for reverse_proxy"
end
matches(path, *args) click to toggle source
# File lib/rack_reverse_proxy/rule.rb, line 46
def matches(path, *args)
  Matches.new(
    spec,
    url,
    path,
    options[:accept_headers],
    has_custom_url,
    *args
  )
end