Created
August 2, 2012 08:50
-
-
Save elia/3235545 to your computer and use it in GitHub Desktop.
Routes deprecations (rails 2)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ActionController::Routing::Route # autoload | |
| class ActionController::Routing::Route | |
| alias initialize_without_deprecation_support initialize | |
| def initialize(segments = [], requirements = {}, conditions = {}) | |
| @deprecated = requirements.delete(:deprecated) | |
| @definition_line = caller.find { |l| l.to_s.include? 'config/routes.rb:' } | |
| initialize_without_deprecation_support(segments, requirements, conditions) | |
| end | |
| def write_recognition! | |
| # Create an if structure to extract the params from a match if it occurs. | |
| body = '' | |
| if deprecated? | |
| deprecation_message = "This route is deprecated: #{to_s.gsub(/ +/, ' ')}" | |
| body += "\n::ActiveSupport::Deprecation.warn(#{deprecation_message.inspect}, [@definition_line])\n" | |
| end | |
| body += "params = parameter_shell.dup\n#{recognition_extraction * "\n"}\nparams" | |
| body = "if #{recognition_conditions.join(" && ")}\n#{body}\nend" | |
| # Build the method declaration and compile it | |
| method_decl = "def recognize(path, env = {})\n#{body}\nend" | |
| instance_eval method_decl, "generated code (#{__FILE__}:#{__LINE__})" | |
| method_decl | |
| end | |
| attr_reader :deprecated | |
| alias deprecated? deprecated | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ActionController::Routing::Routes.draw do |map| | |
| # ... | |
| # DEPRECATED | |
| map.connect '/:controller/:action', :deprecated => true | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment