Class: Swaggable::RackRedirect
- Inherits:
-
Object
- Object
- Swaggable::RackRedirect
- Defined in:
- lib/swaggable/rack_redirect.rb
Instance Attribute Summary collapse
-
#from ⇒ Object
Returns the value of attribute from.
-
#to ⇒ Object
Returns the value of attribute to.
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(first_arg, second_arg = nil) ⇒ RackRedirect
constructor
A new instance of RackRedirect.
Constructor Details
#initialize(first_arg, second_arg = nil) ⇒ RackRedirect
Returns a new instance of RackRedirect.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/swaggable/rack_redirect.rb', line 9 def initialize(first_arg, second_arg = nil) if second_arg next_app = first_arg = second_arg.dup else next_app = nil = first_arg.dup end @next_app = next_app @from = .delete(:from) @to = .delete(:to) || raise(ArgumentError.new(":to option is mandatory")) if .any? raise ArgumentError.new "Unsupported options #{.keys.inspect}" end end |
Instance Attribute Details
#from ⇒ Object
Returns the value of attribute from.
3 4 5 |
# File 'lib/swaggable/rack_redirect.rb', line 3 def from @from end |
#to ⇒ Object
Returns the value of attribute to.
3 4 5 |
# File 'lib/swaggable/rack_redirect.rb', line 3 def to @to end |
Instance Method Details
#call(env) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/swaggable/rack_redirect.rb', line 27 def call env if from.nil? redirect elsif from.is_a?(String) && env['PATH_INFO'] == from redirect elsif from.is_a?(Regexp) && env['PATH_INFO'] =~ from redirect elsif next_app.nil? raise('No application defined to forward the request to') else next_app.call env end end |