Class: Rack::ReverseProxyMatcher
- Inherits:
-
Object
- Object
- Rack::ReverseProxyMatcher
- Defined in:
- lib/rack/reverse_proxy_matcher.rb
Instance Attribute Summary collapse
-
#default_url ⇒ Object
readonly
Returns the value of attribute default_url.
-
#matcher ⇒ Object
readonly
Returns the value of attribute matcher.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
- #get_uri(path, env) ⇒ Object
-
#initialize(matcher, url = nil, options = {}) ⇒ ReverseProxyMatcher
constructor
A new instance of ReverseProxyMatcher.
- #match?(path, *args) ⇒ Boolean
- #to_s ⇒ Object
Constructor Details
#initialize(matcher, url = nil, options = {}) ⇒ ReverseProxyMatcher
Returns a new instance of ReverseProxyMatcher.
3 4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/rack/reverse_proxy_matcher.rb', line 3 def initialize(matcher, url=nil, ={}) @default_url=url @url=url @options= if matcher.kind_of?(String) @matcher = /^#{matcher.to_s}/ elsif matcher.respond_to?(:match) @matcher = matcher else raise "Invalid Matcher for reverse_proxy" end end |
Instance Attribute Details
#default_url ⇒ Object (readonly)
Returns the value of attribute default_url.
17 18 19 |
# File 'lib/rack/reverse_proxy_matcher.rb', line 17 def default_url @default_url end |
#matcher ⇒ Object (readonly)
Returns the value of attribute matcher.
17 18 19 |
# File 'lib/rack/reverse_proxy_matcher.rb', line 17 def matcher @matcher end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
17 18 19 |
# File 'lib/rack/reverse_proxy_matcher.rb', line 17 def @options end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
17 18 19 |
# File 'lib/rack/reverse_proxy_matcher.rb', line 17 def url @url end |
Instance Method Details
#get_uri(path, env) ⇒ Object
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/rack/reverse_proxy_matcher.rb', line 23 def get_uri(path,env) return nil if url.nil? _url=(url.respond_to?(:call) ? url.call(env) : url.clone) if _url =~/\$\d/ match_path(path).to_a.each_with_index { |m, i| _url.gsub!("$#{i.to_s}", m) } URI(_url) else default_url.nil? ? URI.parse(_url) : URI.join(_url, path) end end |
#match?(path, *args) ⇒ Boolean
19 20 21 |
# File 'lib/rack/reverse_proxy_matcher.rb', line 19 def match?(path, *args) match_path(path, *args) ? true : false end |
#to_s ⇒ Object
34 35 36 |
# File 'lib/rack/reverse_proxy_matcher.rb', line 34 def to_s %Q("#{matcher.to_s}" => "#{url}") end |