Skip to content

Instantly share code, notes, and snippets.

@kballenegger
Last active August 29, 2015 14:00
Show Gist options
  • Select an option

  • Save kballenegger/36816df3829a3d4974bc to your computer and use it in GitHub Desktop.

Select an option

Save kballenegger/36816df3829a3d4974bc to your computer and use it in GitHub Desktop.
Overriding wrapping routes with a deprecation message.
require 'kenji'
module Kenji
class Controller
class << self
def routes_deprecated!(enabled = true)
if enabled
puts "Enabling deprecation for the following methods in #{self.name}:"
else
puts "Disabling deprecation in #{self.name}."
end
@deprecation_enabled = enabled
end
old_route = instance_method(:route)
define_method(:route) do |*args, &block|
if @deprecation_enabled
# block -> unbound method
define_method(:_tmp_route_action, &block)
block = instance_method(:_tmp_route_action)
remove_method(:_tmp_route_action)
wrapped = lambda do |*a|
warn "[DEPRECATED] route #{args} was called with args: #{a}"
block.bind(self).call(*a)
end
old_route.bind(self).call(*args, &wrapped)
puts "- route #{args}"
else
old_route.bind(self).call(*args, &block)
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment