mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
ed080863d5
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3533 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
30 lines
No EOL
859 B
Ruby
30 lines
No EOL
859 B
Ruby
# Classes that include this module will automatically be reloaded
|
|
# by the Rails dispatcher when Dependencies.mechanism = :load.
|
|
module Reloadable
|
|
class << self
|
|
def included(base) #nodoc:
|
|
raise TypeError, "Only Classes can be Reloadable!" unless base.is_a? Class
|
|
|
|
unless base.respond_to?(:reloadable?)
|
|
class << base
|
|
define_method(:reloadable?) { true }
|
|
end
|
|
end
|
|
end
|
|
|
|
def reloadable_classes
|
|
included_in_classes.select { |klass| klass.reloadable? }
|
|
end
|
|
end
|
|
|
|
# Captures the common pattern where a base class should not be reloaded,
|
|
# but its subclasses should be.
|
|
module Subclasses
|
|
def self.included(base) #nodoc:
|
|
base.send :include, Reloadable
|
|
(class << base; self; end).send(:define_method, :reloadable?) do
|
|
base != self
|
|
end
|
|
end
|
|
end
|
|
end |