Created
May 18, 2017 08:14
-
-
Save indyarocks/85dea52d8c55c1ecf484094f2bb3585b to your computer and use it in GitHub Desktop.
Railtie.rb snippet from Rails 4.2.5.2(master)
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
module Rails | |
class Railtie | |
# Removed some code | |
class << self | |
private :new | |
delegate :config, to: :instance | |
def inherited(base) | |
unless base.abstract_railtie? | |
subclasses << base | |
end | |
end | |
def rake_tasks(&blk) | |
@rake_tasks ||= [] | |
@rake_tasks << blk if blk | |
@rake_tasks | |
end | |
def console(&blk) | |
@load_console ||= [] | |
@load_console << blk if blk | |
@load_console | |
end | |
def runner(&blk) | |
@load_runner ||= [] | |
@load_runner << blk if blk | |
@load_runner | |
end | |
def generators(&blk) | |
@generators ||= [] | |
@generators << blk if blk | |
@generators | |
end | |
def abstract_railtie? | |
ABSTRACT_RAILTIES.include?(name) | |
end | |
# Since Rails::Railtie cannot be instantiated, any methods that call | |
# +instance+ are intended to be called only on subclasses of a Railtie. | |
def instance | |
@instance ||= new | |
end | |
protected | |
delegate :railtie_name, to: :class | |
def initialize | |
if self.class.abstract_railtie? | |
raise "#{self.class.name} is abstract, you cannot instantiate it directly." | |
end | |
end | |
def config | |
@config ||= Railtie::Configuration.new | |
end | |
def railtie_namespace | |
@railtie_namespace ||= self.class.parents.detect { |n| n.respond_to?(:railtie_namespace) } | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment