radiant/radiant — Issue #312: Problem with extensions and Page.find_by_path
Author: jfahrenkrug
Created: 2012-01-28 00:54:44+00:00
State: open

The new find_by_path method name is problematic when extensions define their own page types that override `find_by_url` because they won't be called.

This is how it is currently:

class Page
def find_by_path
puts "Page.find_by_path"
end

alias_method :find_by_url, :find_by_path
end

class SubPage < Page
def find_by_url
"SubPage.find_by_url"
end
end

Page.new.find_by_path #=>Page.find_by_path
SubPage.new.find_by_path #=>Page.find_by_path

See? When a subclass of Page overrode `find_by_url`, it will never be called. You have to put a reverse `alias_method` into your subclass to make it work:

class Page
def find_by_path
puts "Page.find_by_path"
end

alias_method :find_by_url, :find_by_path
end

class SubPage < Page
def find_by_url
puts "SubPage.find_by_url"
end
alias_method :find_by_path, :find_by_url
end

Page.new.find_by_path #=>Page.find_by_path
SubPage.new.find_by_path #=>SubPage.find_by_url

We should fix this because we don't want to break extensions.