Class: RackReverseProxy::Rule::Matches
- Inherits:
-
Object
- Object
- RackReverseProxy::Rule::Matches
- Defined in:
- lib/rack_reverse_proxy/rule.rb
Overview
Matches represents collection of matched objects for Rule
Instance Method Summary collapse
- #any? ⇒ Boolean
- #custom_url ⇒ Object
-
#initialize(spec, url, path, accept_headers, has_custom_url, headers, rackreq, *_) ⇒ Matches
constructor
FIXME: eliminate :url, :accept_headers, :has_custom_url.
- #substitute(url) ⇒ Object
- #transform(response, request_uri) ⇒ Object
Constructor Details
#initialize(spec, url, path, accept_headers, has_custom_url, headers, rackreq, *_) ⇒ Matches
FIXME: eliminate :url, :accept_headers, :has_custom_url
127 128 129 130 131 132 133 134 135 136 |
# File 'lib/rack_reverse_proxy/rule.rb', line 127 def initialize(spec, url, path, accept_headers, has_custom_url, headers, rackreq, *_) @spec = spec @url = url @path = path @has_custom_url = has_custom_url @rackreq = rackreq @headers = headers if accept_headers @spec_arity = spec.method(spec_match_method_name).arity end |
Instance Method Details
#any? ⇒ Boolean
138 139 140 |
# File 'lib/rack_reverse_proxy/rule.rb', line 138 def any? found.any? end |
#custom_url ⇒ Object
142 143 144 145 146 147 |
# File 'lib/rack_reverse_proxy/rule.rb', line 142 def custom_url return url unless has_custom_url found.map do |match| match.url(path) end.first end |
#substitute(url) ⇒ Object
149 150 151 152 153 |
# File 'lib/rack_reverse_proxy/rule.rb', line 149 def substitute(url) found.each_with_index.inject(url) do |acc, (match, i)| acc.gsub("$#{i}", match) end end |
#transform(response, request_uri) ⇒ Object
155 156 157 158 159 160 161 162 163 |
# File 'lib/rack_reverse_proxy/rule.rb', line 155 def transform(response, request_uri) found.inject(response) do |accumulator, match| if match.respond_to?(:transform) match.transform(accumulator, request_uri) else accumulator end end end |