Class: Rack::Rewrite
- Inherits:
-
Object
- Object
- Rack::Rewrite
- Defined in:
- lib/rack/rewrite.rb,
lib/rack/rewrite/rule.rb,
lib/rack/rewrite/version.rb
Overview
A rack middleware for defining and applying rewrite rules. In many cases you can get away with rack-rewrite instead of writing Apache mod_rewrite rules.
Defined Under Namespace
Constant Summary collapse
- VERSION =
File.read File.join(File.("..", __FILE__), "..", "..", "..", "VERSION")
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, given_options = {}, &rule_block) ⇒ Rewrite
constructor
A new instance of Rewrite.
Constructor Details
#initialize(app, given_options = {}, &rule_block) ⇒ Rewrite
Returns a new instance of Rewrite.
8 9 10 11 12 13 14 15 16 |
# File 'lib/rack/rewrite.rb', line 8 def initialize(app, = {}, &rule_block) = { :klass => RuleSet, :options => {} }.merge() @app = app @rule_set = [:klass].new([:options]) @rule_set.instance_eval(&rule_block) if block_given? end |
Instance Method Details
#call(env) ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/rack/rewrite.rb', line 18 def call(env) if matched_rule = find_first_matching_rule(env) rack_response = matched_rule.apply!(env) # Don't invoke the app if applying the rule returns a rack response return rack_response unless rack_response === true end @app.call(env) end |