2010-01-23 16:30:17 -05:00
|
|
|
require 'rails/railtie'
|
2013-02-27 10:11:43 -05:00
|
|
|
require 'rails/engine/railties'
|
2010-03-01 22:29:12 -05:00
|
|
|
require 'active_support/core_ext/module/delegation'
|
|
|
|
require 'pathname'
|
2010-01-21 17:14:20 -05:00
|
|
|
|
|
|
|
module Rails
|
2013-08-06 15:16:03 -04:00
|
|
|
# <tt>Rails::Engine</tt> allows you to wrap a specific Rails application or subset of
|
2012-09-21 12:57:15 -04:00
|
|
|
# functionality and share it with other applications or within a larger packaged application.
|
2013-08-06 15:16:03 -04:00
|
|
|
# Since Rails 3.0, every <tt>Rails::Application</tt> is just an engine, which allows for simple
|
2011-07-12 09:54:43 -04:00
|
|
|
# feature and application sharing.
|
2010-02-02 14:05:26 -05:00
|
|
|
#
|
2013-08-06 15:16:03 -04:00
|
|
|
# Any <tt>Rails::Engine</tt> is also a <tt>Rails::Railtie</tt>, so the same
|
|
|
|
# methods (like <tt>rake_tasks</tt> and +generators+) and configuration
|
2011-07-12 09:54:43 -04:00
|
|
|
# options that are available in railties can also be used in engines.
|
2010-02-02 14:05:26 -05:00
|
|
|
#
|
|
|
|
# == Creating an Engine
|
|
|
|
#
|
2011-01-19 15:30:28 -05:00
|
|
|
# In Rails versions prior to 3.0, your gems automatically behaved as engines, however,
|
2010-02-02 14:05:26 -05:00
|
|
|
# this coupled Rails to Rubygems. Since Rails 3.0, if you want a gem to automatically
|
2011-01-19 15:30:28 -05:00
|
|
|
# behave as an engine, you have to specify an +Engine+ for it somewhere inside
|
|
|
|
# your plugin's +lib+ folder (similar to how we specify a +Railtie+):
|
2010-02-02 14:05:26 -05:00
|
|
|
#
|
|
|
|
# # lib/my_engine.rb
|
|
|
|
# module MyEngine
|
|
|
|
# class Engine < Rails::Engine
|
|
|
|
# end
|
|
|
|
# end
|
|
|
|
#
|
2013-08-06 15:16:03 -04:00
|
|
|
# Then ensure that this file is loaded at the top of your <tt>config/application.rb</tt>
|
2011-01-19 15:30:28 -05:00
|
|
|
# (or in your +Gemfile+) and it will automatically load models, controllers and helpers
|
2013-08-06 15:16:03 -04:00
|
|
|
# inside +app+, load routes at <tt>config/routes.rb</tt>, load locales at
|
|
|
|
# <tt>config/locales/*</tt>, and load tasks at <tt>lib/tasks/*</tt>.
|
2010-02-02 14:05:26 -05:00
|
|
|
#
|
|
|
|
# == Configuration
|
|
|
|
#
|
2011-01-19 15:30:28 -05:00
|
|
|
# Besides the +Railtie+ configuration which is shared across the application, in a
|
2013-08-06 15:16:03 -04:00
|
|
|
# <tt>Rails::Engine</tt> you can access <tt>autoload_paths</tt>, <tt>eager_load_paths</tt>
|
|
|
|
# and <tt>autoload_once_paths</tt>, which, differently from a <tt>Railtie</tt>, are scoped to
|
2013-02-19 02:22:37 -05:00
|
|
|
# the current engine.
|
2010-02-02 14:05:26 -05:00
|
|
|
#
|
|
|
|
# class MyEngine < Rails::Engine
|
|
|
|
# # Add a load path for this specific Engine
|
2010-06-22 17:17:20 -04:00
|
|
|
# config.autoload_paths << File.expand_path("../lib/some/path", __FILE__)
|
2010-04-05 18:32:03 -04:00
|
|
|
#
|
|
|
|
# initializer "my_engine.add_middleware" do |app|
|
2010-04-29 14:43:09 -04:00
|
|
|
# app.middleware.use MyEngine::Middleware
|
2010-04-05 18:32:03 -04:00
|
|
|
# end
|
2010-02-02 14:05:26 -05:00
|
|
|
# end
|
2010-05-15 09:08:55 -04:00
|
|
|
#
|
2010-09-30 13:17:36 -04:00
|
|
|
# == Generators
|
|
|
|
#
|
2013-08-06 15:16:03 -04:00
|
|
|
# You can set up generators for engines with <tt>config.generators</tt> method:
|
2010-09-30 13:17:36 -04:00
|
|
|
#
|
|
|
|
# class MyEngine < Rails::Engine
|
|
|
|
# config.generators do |g|
|
|
|
|
# g.orm :active_record
|
|
|
|
# g.template_engine :erb
|
|
|
|
# g.test_framework :test_unit
|
|
|
|
# end
|
|
|
|
# end
|
|
|
|
#
|
2013-08-06 15:16:03 -04:00
|
|
|
# You can also set generators for an application by using <tt>config.app_generators</tt>:
|
2010-09-30 13:17:36 -04:00
|
|
|
#
|
|
|
|
# class MyEngine < Rails::Engine
|
|
|
|
# # note that you can also pass block to app_generators in the same way you
|
|
|
|
# # can pass it to generators method
|
|
|
|
# config.app_generators.orm :datamapper
|
|
|
|
# end
|
|
|
|
#
|
2010-02-02 14:05:26 -05:00
|
|
|
# == Paths
|
|
|
|
#
|
2011-07-12 09:54:43 -04:00
|
|
|
# Since Rails 3.0, applications and engines have more flexible path configuration (as
|
2011-07-19 14:24:48 -04:00
|
|
|
# opposed to the previous hardcoded path configuration). This means that you are not
|
2013-08-06 15:16:03 -04:00
|
|
|
# required to place your controllers at <tt>app/controllers</tt>, but in any place
|
2011-07-12 09:54:43 -04:00
|
|
|
# which you find convenient.
|
2010-02-02 14:05:26 -05:00
|
|
|
#
|
2013-08-06 15:16:03 -04:00
|
|
|
# For example, let's suppose you want to place your controllers in <tt>lib/controllers</tt>.
|
2011-07-12 09:54:43 -04:00
|
|
|
# You can set that as an option:
|
2010-02-02 14:05:26 -05:00
|
|
|
#
|
|
|
|
# class MyEngine < Rails::Engine
|
2010-10-11 04:29:31 -04:00
|
|
|
# paths["app/controllers"] = "lib/controllers"
|
2010-02-02 14:05:26 -05:00
|
|
|
# end
|
|
|
|
#
|
2013-08-06 15:16:03 -04:00
|
|
|
# You can also have your controllers loaded from both <tt>app/controllers</tt> and
|
|
|
|
# <tt>lib/controllers</tt>:
|
2010-02-02 14:05:26 -05:00
|
|
|
#
|
|
|
|
# class MyEngine < Rails::Engine
|
2010-10-11 04:29:31 -04:00
|
|
|
# paths["app/controllers"] << "lib/controllers"
|
2010-02-02 14:05:26 -05:00
|
|
|
# end
|
|
|
|
#
|
2011-01-19 15:30:28 -05:00
|
|
|
# The available paths in an engine are:
|
2010-02-02 14:05:26 -05:00
|
|
|
#
|
|
|
|
# class MyEngine < Rails::Engine
|
2011-05-04 14:08:21 -04:00
|
|
|
# paths["app"] # => ["app"]
|
|
|
|
# paths["app/controllers"] # => ["app/controllers"]
|
|
|
|
# paths["app/helpers"] # => ["app/helpers"]
|
|
|
|
# paths["app/models"] # => ["app/models"]
|
|
|
|
# paths["app/views"] # => ["app/views"]
|
|
|
|
# paths["lib"] # => ["lib"]
|
|
|
|
# paths["lib/tasks"] # => ["lib/tasks"]
|
|
|
|
# paths["config"] # => ["config"]
|
|
|
|
# paths["config/initializers"] # => ["config/initializers"]
|
|
|
|
# paths["config/locales"] # => ["config/locales"]
|
2013-08-23 07:27:37 -04:00
|
|
|
# paths["config/routes.rb"] # => ["config/routes.rb"]
|
2010-02-02 14:05:26 -05:00
|
|
|
# end
|
|
|
|
#
|
2013-08-06 15:16:03 -04:00
|
|
|
# The <tt>Application</tt> class adds a couple more paths to this set. And as in your
|
|
|
|
# <tt>Application</tt>, all folders under +app+ are automatically added to the load path.
|
|
|
|
# If you have an <tt>app/services</tt> folder for example, it will be added by default.
|
2010-02-02 14:05:26 -05:00
|
|
|
#
|
2010-07-22 05:26:36 -04:00
|
|
|
# == Endpoint
|
|
|
|
#
|
2011-01-19 15:30:28 -05:00
|
|
|
# An engine can be also a rack application. It can be useful if you have a rack application that
|
|
|
|
# you would like to wrap with +Engine+ and provide some of the +Engine+'s features.
|
2010-07-22 05:26:36 -04:00
|
|
|
#
|
2011-01-19 15:30:28 -05:00
|
|
|
# To do that, use the +endpoint+ method:
|
2011-01-14 03:34:59 -05:00
|
|
|
#
|
2010-07-22 05:26:36 -04:00
|
|
|
# module MyEngine
|
|
|
|
# class Engine < Rails::Engine
|
|
|
|
# endpoint MyRackApplication
|
|
|
|
# end
|
|
|
|
# end
|
|
|
|
#
|
2011-01-19 15:30:28 -05:00
|
|
|
# Now you can mount your engine in application's routes just like that:
|
2010-07-22 05:26:36 -04:00
|
|
|
#
|
2013-04-30 12:26:55 -04:00
|
|
|
# Rails.application.routes.draw do
|
2011-01-14 03:34:59 -05:00
|
|
|
# mount MyEngine::Engine => "/engine"
|
|
|
|
# end
|
2010-07-22 05:26:36 -04:00
|
|
|
#
|
|
|
|
# == Middleware stack
|
|
|
|
#
|
2011-07-12 09:54:43 -04:00
|
|
|
# As an engine can now be a rack endpoint, it can also have a middleware
|
2013-08-06 15:16:03 -04:00
|
|
|
# stack. The usage is exactly the same as in <tt>Application</tt>:
|
2010-07-22 05:26:36 -04:00
|
|
|
#
|
|
|
|
# module MyEngine
|
|
|
|
# class Engine < Rails::Engine
|
|
|
|
# middleware.use SomeMiddleware
|
|
|
|
# end
|
|
|
|
# end
|
|
|
|
#
|
|
|
|
# == Routes
|
|
|
|
#
|
2011-07-12 09:54:43 -04:00
|
|
|
# If you don't specify an endpoint, routes will be used as the default
|
|
|
|
# endpoint. You can use them just like you use an application's routes:
|
2010-07-22 05:26:36 -04:00
|
|
|
#
|
2010-09-03 18:52:07 -04:00
|
|
|
# # ENGINE/config/routes.rb
|
|
|
|
# MyEngine::Engine.routes.draw do
|
2012-04-24 23:32:09 -04:00
|
|
|
# get "/" => "posts#index"
|
2010-09-03 18:52:07 -04:00
|
|
|
# end
|
2010-07-22 05:26:36 -04:00
|
|
|
#
|
|
|
|
# == Mount priority
|
|
|
|
#
|
2011-01-14 03:34:59 -05:00
|
|
|
# Note that now there can be more than one router in your application, and it's better to avoid
|
|
|
|
# passing requests through many routers. Consider this situation:
|
2010-07-22 05:26:36 -04:00
|
|
|
#
|
2013-04-30 12:26:55 -04:00
|
|
|
# Rails.application.routes.draw do
|
2010-09-03 18:52:07 -04:00
|
|
|
# mount MyEngine::Engine => "/blog"
|
2012-04-24 23:32:09 -04:00
|
|
|
# get "/blog/omg" => "main#omg"
|
2010-09-03 18:52:07 -04:00
|
|
|
# end
|
2010-07-22 05:26:36 -04:00
|
|
|
#
|
2013-08-06 15:16:03 -04:00
|
|
|
# +MyEngine+ is mounted at <tt>/blog</tt>, and <tt>/blog/omg</tt> points to application's
|
|
|
|
# controller. In such a situation, requests to <tt>/blog/omg</tt> will go through +MyEngine+,
|
|
|
|
# and if there is no such route in +Engine+'s routes, it will be dispatched to <tt>main#omg</tt>.
|
2011-01-14 03:34:59 -05:00
|
|
|
# It's much better to swap that:
|
2010-07-22 05:26:36 -04:00
|
|
|
#
|
2013-04-30 12:26:55 -04:00
|
|
|
# Rails.application.routes.draw do
|
2012-04-24 23:32:09 -04:00
|
|
|
# get "/blog/omg" => "main#omg"
|
2010-09-03 18:52:07 -04:00
|
|
|
# mount MyEngine::Engine => "/blog"
|
|
|
|
# end
|
2010-07-22 05:26:36 -04:00
|
|
|
#
|
2011-01-19 15:30:28 -05:00
|
|
|
# Now, +Engine+ will get only requests that were not handled by +Application+.
|
2010-07-22 05:26:36 -04:00
|
|
|
#
|
2010-08-03 17:52:58 -04:00
|
|
|
# == Engine name
|
|
|
|
#
|
2011-01-14 03:34:59 -05:00
|
|
|
# There are some places where an Engine's name is used:
|
2011-07-23 06:14:10 -04:00
|
|
|
#
|
2013-08-06 15:16:03 -04:00
|
|
|
# * routes: when you mount an Engine with <tt>mount(MyEngine::Engine => '/my_engine')</tt>,
|
|
|
|
# it's used as default <tt>:as</tt> option
|
|
|
|
# * rake task for installing migrations <tt>my_engine:install:migrations</tt>
|
2010-08-03 17:52:58 -04:00
|
|
|
#
|
2013-08-06 15:16:03 -04:00
|
|
|
# Engine name is set by default based on class name. For <tt>MyEngine::Engine</tt> it will be
|
|
|
|
# <tt>my_engine_engine</tt>. You can change it manually using the <tt>engine_name</tt> method:
|
2010-08-03 17:52:58 -04:00
|
|
|
#
|
2010-09-03 18:52:07 -04:00
|
|
|
# module MyEngine
|
|
|
|
# class Engine < Rails::Engine
|
|
|
|
# engine_name "my_engine"
|
|
|
|
# end
|
2010-08-03 17:52:58 -04:00
|
|
|
# end
|
|
|
|
#
|
2010-12-15 03:09:29 -05:00
|
|
|
# == Isolated Engine
|
2010-08-03 16:54:56 -04:00
|
|
|
#
|
2011-01-14 03:34:59 -05:00
|
|
|
# Normally when you create controllers, helpers and models inside an engine, they are treated
|
2011-07-12 09:54:43 -04:00
|
|
|
# as if they were created inside the application itself. This means that all helpers and
|
|
|
|
# named routes from the application will be available to your engine's controllers as well.
|
2010-10-11 04:29:31 -04:00
|
|
|
#
|
2011-01-14 03:34:59 -05:00
|
|
|
# However, sometimes you want to isolate your engine from the application, especially if your engine
|
|
|
|
# has its own router. To do that, you simply need to call +isolate_namespace+. This method requires
|
2010-10-11 04:29:31 -04:00
|
|
|
# you to pass a module where all your controllers, helpers and models should be nested to:
|
2010-08-03 16:54:56 -04:00
|
|
|
#
|
2010-09-03 18:52:07 -04:00
|
|
|
# module MyEngine
|
|
|
|
# class Engine < Rails::Engine
|
2010-10-09 14:59:20 -04:00
|
|
|
# isolate_namespace MyEngine
|
2010-09-03 18:52:07 -04:00
|
|
|
# end
|
2010-08-03 16:54:56 -04:00
|
|
|
# end
|
|
|
|
#
|
2011-01-19 15:30:28 -05:00
|
|
|
# With such an engine, everything that is inside the +MyEngine+ module will be isolated from
|
2011-01-14 03:34:59 -05:00
|
|
|
# the application.
|
2010-08-03 16:54:56 -04:00
|
|
|
#
|
|
|
|
# Consider such controller:
|
|
|
|
#
|
2010-09-03 18:52:07 -04:00
|
|
|
# module MyEngine
|
|
|
|
# class FooController < ActionController::Base
|
|
|
|
# end
|
2010-08-03 16:54:56 -04:00
|
|
|
# end
|
|
|
|
#
|
2011-01-19 15:30:28 -05:00
|
|
|
# If an engine is marked as isolated, +FooController+ has access only to helpers from +Engine+ and
|
2013-08-06 15:16:03 -04:00
|
|
|
# <tt>url_helpers</tt> from <tt>MyEngine::Engine.routes</tt>.
|
2010-08-03 16:54:56 -04:00
|
|
|
#
|
2011-07-24 06:21:42 -04:00
|
|
|
# The next thing that changes in isolated engines is the behavior of routes. Normally, when you namespace
|
2011-01-14 03:34:59 -05:00
|
|
|
# your controllers, you also need to do namespace all your routes. With an isolated engine,
|
2010-10-11 04:29:31 -04:00
|
|
|
# the namespace is applied by default, so you can ignore it in routes:
|
|
|
|
#
|
|
|
|
# MyEngine::Engine.routes.draw do
|
|
|
|
# resources :articles
|
|
|
|
# end
|
2011-01-14 03:34:59 -05:00
|
|
|
#
|
2013-08-06 15:16:03 -04:00
|
|
|
# The routes above will automatically point to <tt>MyEngine::ArticlesController</tt>. Furthermore, you don't
|
|
|
|
# need to use longer url helpers like <tt>my_engine_articles_path</tt>. Instead, you should simply use
|
|
|
|
# <tt>articles_path</tt> as you would do with your application.
|
2011-01-14 03:34:59 -05:00
|
|
|
#
|
2011-07-24 06:21:42 -04:00
|
|
|
# To make that behavior consistent with other parts of the framework, an isolated engine also has influence on
|
2013-08-06 15:16:03 -04:00
|
|
|
# <tt>ActiveModel::Naming</tt>. When you use a namespaced model, like <tt>MyEngine::Article</tt>, it will normally
|
2011-03-04 00:19:58 -05:00
|
|
|
# use the prefix "my_engine". In an isolated engine, the prefix will be omitted in url helpers and
|
2010-10-11 04:29:31 -04:00
|
|
|
# form fields for convenience.
|
2010-09-20 15:27:43 -04:00
|
|
|
#
|
2011-05-04 14:08:21 -04:00
|
|
|
# polymorphic_url(MyEngine::Article.new) # => "articles_path"
|
2010-09-20 15:27:43 -04:00
|
|
|
#
|
|
|
|
# form_for(MyEngine::Article.new) do
|
2011-05-04 14:08:21 -04:00
|
|
|
# text_field :title # => <input type="text" name="article[title]" id="article_title" />
|
2010-09-20 15:27:43 -04:00
|
|
|
# end
|
|
|
|
#
|
2011-07-12 09:54:43 -04:00
|
|
|
# Additionally, an isolated engine will set its name according to namespace, so
|
2011-05-04 14:08:21 -04:00
|
|
|
# MyEngine::Engine.engine_name will be "my_engine". It will also set MyEngine.table_name_prefix
|
2012-03-06 07:03:36 -05:00
|
|
|
# to "my_engine_", changing the MyEngine::Article model to use the my_engine_articles table.
|
2010-08-03 16:54:56 -04:00
|
|
|
#
|
2010-08-03 18:03:26 -04:00
|
|
|
# == Using Engine's routes outside Engine
|
|
|
|
#
|
2011-01-19 15:30:28 -05:00
|
|
|
# Since you can now mount an engine inside application's routes, you do not have direct access to +Engine+'s
|
2013-08-06 15:16:03 -04:00
|
|
|
# <tt>url_helpers</tt> inside +Application+. When you mount an engine in an application's routes, a special helper is
|
2011-01-14 03:34:59 -05:00
|
|
|
# created to allow you to do that. Consider such a scenario:
|
2010-08-03 18:03:26 -04:00
|
|
|
#
|
2011-05-04 14:08:21 -04:00
|
|
|
# # config/routes.rb
|
2013-04-30 12:26:55 -04:00
|
|
|
# Rails.application.routes.draw do
|
2012-10-14 06:03:39 -04:00
|
|
|
# mount MyEngine::Engine => "/my_engine", as: "my_engine"
|
2012-04-24 23:32:09 -04:00
|
|
|
# get "/foo" => "foo#index"
|
2010-09-03 18:52:07 -04:00
|
|
|
# end
|
2010-08-03 18:03:26 -04:00
|
|
|
#
|
2013-08-06 15:16:03 -04:00
|
|
|
# Now, you can use the <tt>my_engine</tt> helper inside your application:
|
2010-08-03 18:03:26 -04:00
|
|
|
#
|
2010-09-03 18:52:07 -04:00
|
|
|
# class FooController < ApplicationController
|
|
|
|
# def index
|
2013-11-11 13:53:54 -05:00
|
|
|
# my_engine.root_url # => /my_engine/
|
2010-09-03 18:52:07 -04:00
|
|
|
# end
|
2010-08-03 18:03:26 -04:00
|
|
|
# end
|
|
|
|
#
|
2013-08-06 15:16:03 -04:00
|
|
|
# There is also a <tt>main_app</tt> helper that gives you access to application's routes inside Engine:
|
2010-08-03 18:03:26 -04:00
|
|
|
#
|
2010-09-03 18:52:07 -04:00
|
|
|
# module MyEngine
|
|
|
|
# class BarController
|
2010-10-11 04:29:31 -04:00
|
|
|
# def index
|
2013-11-11 13:53:54 -05:00
|
|
|
# main_app.foo_path # => /foo
|
2010-10-11 04:29:31 -04:00
|
|
|
# end
|
2010-09-03 18:52:07 -04:00
|
|
|
# end
|
2010-08-03 18:03:26 -04:00
|
|
|
# end
|
|
|
|
#
|
2013-08-06 15:16:03 -04:00
|
|
|
# Note that the <tt>:as</tt> option given to mount takes the <tt>engine_name</tt> as default, so most of the time
|
2011-01-14 03:34:59 -05:00
|
|
|
# you can simply omit it.
|
2010-08-25 13:02:21 -04:00
|
|
|
#
|
2011-07-12 09:54:43 -04:00
|
|
|
# Finally, if you want to generate a url to an engine's route using
|
2013-08-06 15:16:03 -04:00
|
|
|
# <tt>polymorphic_url</tt>, you also need to pass the engine helper. Let's
|
2011-07-12 09:54:43 -04:00
|
|
|
# say that you want to create a form pointing to one of the engine's routes.
|
|
|
|
# All you need to do is pass the helper as the first element in array with
|
2010-10-11 04:29:31 -04:00
|
|
|
# attributes for url:
|
2010-08-25 13:02:21 -04:00
|
|
|
#
|
2011-01-14 03:34:59 -05:00
|
|
|
# form_for([my_engine, @user])
|
2010-08-25 13:02:21 -04:00
|
|
|
#
|
2013-08-06 15:16:03 -04:00
|
|
|
# This code will use <tt>my_engine.user_path(@user)</tt> to generate the proper route.
|
2010-08-25 13:02:21 -04:00
|
|
|
#
|
2011-04-25 07:12:07 -04:00
|
|
|
# == Isolated engine's helpers
|
|
|
|
#
|
|
|
|
# Sometimes you may want to isolate engine, but use helpers that are defined for it.
|
|
|
|
# If you want to share just a few specific helpers you can add them to application's
|
|
|
|
# helpers in ApplicationController:
|
|
|
|
#
|
2011-11-10 12:52:39 -05:00
|
|
|
# class ApplicationController < ActionController::Base
|
|
|
|
# helper MyEngine::SharedEngineHelper
|
|
|
|
# end
|
2011-04-25 07:12:07 -04:00
|
|
|
#
|
2012-02-12 21:54:21 -05:00
|
|
|
# If you want to include all of the engine's helpers, you can use #helper method on an engine's
|
2011-04-25 07:12:07 -04:00
|
|
|
# instance:
|
|
|
|
#
|
2011-11-10 12:52:39 -05:00
|
|
|
# class ApplicationController < ActionController::Base
|
|
|
|
# helper MyEngine::Engine.helpers
|
|
|
|
# end
|
2011-04-25 07:12:07 -04:00
|
|
|
#
|
|
|
|
# It will include all of the helpers from engine's directory. Take into account that this does
|
|
|
|
# not include helpers defined in controllers with helper_method or other similar solutions,
|
2011-05-22 21:17:38 -04:00
|
|
|
# only helpers defined in the helpers directory will be included.
|
2011-04-25 07:12:07 -04:00
|
|
|
#
|
2010-09-19 12:47:41 -04:00
|
|
|
# == Migrations & seed data
|
|
|
|
#
|
2011-01-14 03:34:59 -05:00
|
|
|
# Engines can have their own migrations. The default path for migrations is exactly the same
|
2013-08-06 15:16:03 -04:00
|
|
|
# as in application: <tt>db/migrate</tt>
|
2010-09-19 12:47:41 -04:00
|
|
|
#
|
|
|
|
# To use engine's migrations in application you can use rake task, which copies them to
|
|
|
|
# application's dir:
|
|
|
|
#
|
2010-10-11 04:29:31 -04:00
|
|
|
# rake ENGINE_NAME:install:migrations
|
2010-09-19 12:47:41 -04:00
|
|
|
#
|
2011-01-14 03:34:59 -05:00
|
|
|
# Note that some of the migrations may be skipped if a migration with the same name already exists
|
|
|
|
# in application. In such a situation you must decide whether to leave that migration or rename the
|
2011-07-12 09:54:43 -04:00
|
|
|
# migration in the application and rerun copying migrations.
|
2010-10-13 16:14:15 -04:00
|
|
|
#
|
2010-09-19 12:47:41 -04:00
|
|
|
# If your engine has migrations, you may also want to prepare data for the database in
|
2013-08-06 15:16:03 -04:00
|
|
|
# the <tt>db/seeds.rb</tt> file. You can load that data using the <tt>load_seed</tt> method, e.g.
|
2010-09-19 12:47:41 -04:00
|
|
|
#
|
|
|
|
# MyEngine::Engine.load_seed
|
|
|
|
#
|
2011-11-22 17:26:27 -05:00
|
|
|
# == Loading priority
|
|
|
|
#
|
2012-04-28 01:46:45 -04:00
|
|
|
# In order to change engine's priority you can use +config.railties_order+ in main application.
|
2011-11-22 17:26:27 -05:00
|
|
|
# It will affect the priority of loading views, helpers, assets and all the other files
|
|
|
|
# related to engine or application.
|
|
|
|
#
|
|
|
|
# # load Blog::Engine with highest priority, followed by application and other railties
|
|
|
|
# config.railties_order = [Blog::Engine, :main_app, :all]
|
2010-01-21 17:14:20 -05:00
|
|
|
class Engine < Railtie
|
2010-01-23 16:30:17 -05:00
|
|
|
autoload :Configuration, "rails/engine/configuration"
|
2010-01-23 12:41:53 -05:00
|
|
|
|
2010-01-21 17:14:20 -05:00
|
|
|
class << self
|
2010-10-09 14:59:20 -04:00
|
|
|
attr_accessor :called_from, :isolated
|
2012-08-01 14:54:22 -04:00
|
|
|
|
2010-11-14 20:32:43 -05:00
|
|
|
alias :isolated? :isolated
|
2010-07-26 12:32:42 -04:00
|
|
|
alias :engine_name :railtie_name
|
2010-01-21 17:14:20 -05:00
|
|
|
|
2012-08-01 14:54:22 -04:00
|
|
|
delegate :eager_load!, to: :instance
|
|
|
|
|
2010-01-21 17:14:20 -05:00
|
|
|
def inherited(base)
|
2010-03-26 09:41:40 -04:00
|
|
|
unless base.abstract_railtie?
|
2012-08-01 14:54:22 -04:00
|
|
|
Rails::Railtie::Configuration.eager_load_namespaces << base
|
|
|
|
|
2010-01-23 12:41:53 -05:00
|
|
|
base.called_from = begin
|
2013-07-22 00:49:50 -04:00
|
|
|
call_stack = if Kernel.respond_to?(:caller_locations)
|
|
|
|
caller_locations.map(&:path)
|
|
|
|
else
|
|
|
|
# Remove the line number from backtraces making sure we don't leave anything behind
|
|
|
|
caller.map { |p| p.sub(/:\d+.*/, '') }
|
|
|
|
end
|
|
|
|
|
2010-10-15 10:31:00 -04:00
|
|
|
File.dirname(call_stack.detect { |p| p !~ %r[railties[\w.-]*/lib/rails|rack[\w.-]*/lib/rack] })
|
2010-01-23 12:41:53 -05:00
|
|
|
end
|
2010-01-21 17:14:20 -05:00
|
|
|
end
|
2010-01-23 12:41:53 -05:00
|
|
|
|
2010-01-21 17:14:20 -05:00
|
|
|
super
|
|
|
|
end
|
|
|
|
|
2010-07-08 06:07:25 -04:00
|
|
|
def endpoint(endpoint = nil)
|
2011-08-24 16:25:11 -04:00
|
|
|
@endpoint ||= nil
|
2010-07-08 06:07:25 -04:00
|
|
|
@endpoint = endpoint if endpoint
|
|
|
|
@endpoint
|
|
|
|
end
|
2010-07-30 01:14:48 -04:00
|
|
|
|
2010-10-09 14:59:20 -04:00
|
|
|
def isolate_namespace(mod)
|
2014-02-26 18:43:20 -05:00
|
|
|
engine_name(generate_railtie_name(mod.name))
|
2010-08-03 16:36:12 -04:00
|
|
|
|
2012-10-14 06:03:39 -04:00
|
|
|
self.routes.default_scope = { module: ActiveSupport::Inflector.underscore(mod.name) }
|
2010-10-09 14:59:20 -04:00
|
|
|
self.isolated = true
|
2010-09-25 13:02:14 -04:00
|
|
|
|
2011-11-23 14:06:45 -05:00
|
|
|
unless mod.respond_to?(:railtie_namespace)
|
|
|
|
name, railtie = engine_name, self
|
|
|
|
|
2010-09-25 13:02:14 -04:00
|
|
|
mod.singleton_class.instance_eval do
|
2011-11-23 14:06:45 -05:00
|
|
|
define_method(:railtie_namespace) { railtie }
|
2010-09-25 13:02:14 -04:00
|
|
|
|
2010-11-20 20:20:09 -05:00
|
|
|
unless mod.respond_to?(:table_name_prefix)
|
2011-11-23 14:06:45 -05:00
|
|
|
define_method(:table_name_prefix) { "#{name}_" }
|
|
|
|
end
|
|
|
|
|
|
|
|
unless mod.respond_to?(:use_relative_model_naming?)
|
|
|
|
class_eval "def use_relative_model_naming?; true; end", __FILE__, __LINE__
|
|
|
|
end
|
|
|
|
|
|
|
|
unless mod.respond_to?(:railtie_helpers_paths)
|
|
|
|
define_method(:railtie_helpers_paths) { railtie.helpers_paths }
|
|
|
|
end
|
|
|
|
|
|
|
|
unless mod.respond_to?(:railtie_routes_url_helpers)
|
2012-06-29 10:50:51 -04:00
|
|
|
define_method(:railtie_routes_url_helpers) { railtie.routes.url_helpers }
|
2010-09-25 13:02:14 -04:00
|
|
|
end
|
2011-11-23 14:06:45 -05:00
|
|
|
end
|
2010-09-25 13:02:14 -04:00
|
|
|
end
|
2010-08-23 13:25:04 -04:00
|
|
|
end
|
2010-12-08 17:15:13 -05:00
|
|
|
|
|
|
|
# Finds engine with given path
|
|
|
|
def find(path)
|
2012-05-23 18:56:49 -04:00
|
|
|
expanded_path = File.expand_path path
|
2012-06-29 09:25:47 -04:00
|
|
|
Rails::Engine.subclasses.each do |klass|
|
|
|
|
engine = klass.instance
|
|
|
|
return engine if File.expand_path(engine.root) == expanded_path
|
|
|
|
end
|
|
|
|
nil
|
2010-12-08 17:15:13 -05:00
|
|
|
end
|
2010-01-21 17:14:20 -05:00
|
|
|
end
|
|
|
|
|
2012-10-14 06:03:39 -04:00
|
|
|
delegate :middleware, :root, :paths, to: :config
|
2013-01-06 04:43:30 -05:00
|
|
|
delegate :engine_name, :isolated?, to: :class
|
2010-01-23 11:51:48 -05:00
|
|
|
|
2012-06-29 10:50:51 -04:00
|
|
|
def initialize
|
|
|
|
@_all_autoload_paths = nil
|
|
|
|
@_all_load_paths = nil
|
|
|
|
@app = nil
|
|
|
|
@config = nil
|
|
|
|
@env_config = nil
|
|
|
|
@helpers = nil
|
|
|
|
@routes = nil
|
2010-02-28 17:39:01 -05:00
|
|
|
super
|
2010-01-23 11:51:48 -05:00
|
|
|
end
|
2011-07-24 06:21:42 -04:00
|
|
|
|
2012-06-29 10:50:51 -04:00
|
|
|
# Load console and invoke the registered hooks.
|
2013-08-06 15:16:03 -04:00
|
|
|
# Check <tt>Rails::Railtie.console</tt> for more info.
|
2011-06-16 13:52:05 -04:00
|
|
|
def load_console(app=self)
|
2012-06-29 10:50:51 -04:00
|
|
|
require "pp"
|
|
|
|
require "rails/console/app"
|
|
|
|
require "rails/console/helpers"
|
|
|
|
run_console_blocks(app)
|
|
|
|
self
|
2011-06-16 13:52:05 -04:00
|
|
|
end
|
2011-07-24 06:21:42 -04:00
|
|
|
|
2012-06-29 10:50:51 -04:00
|
|
|
# Load Rails runner and invoke the registered hooks.
|
2013-08-06 15:16:03 -04:00
|
|
|
# Check <tt>Rails::Railtie.runner</tt> for more info.
|
2012-05-29 10:31:27 -04:00
|
|
|
def load_runner(app=self)
|
2012-06-29 10:50:51 -04:00
|
|
|
run_runner_blocks(app)
|
|
|
|
self
|
2012-05-29 10:31:27 -04:00
|
|
|
end
|
|
|
|
|
2012-06-29 10:50:51 -04:00
|
|
|
# Load Rake, railties tasks and invoke the registered hooks.
|
2013-08-06 15:16:03 -04:00
|
|
|
# Check <tt>Rails::Railtie.rake_tasks</tt> for more info.
|
2012-06-29 10:50:51 -04:00
|
|
|
def load_tasks(app=self)
|
|
|
|
require "rake"
|
|
|
|
run_tasks_blocks(app)
|
|
|
|
self
|
|
|
|
end
|
2011-07-24 06:21:42 -04:00
|
|
|
|
2013-05-09 07:57:08 -04:00
|
|
|
# Load Rails generators and invoke the registered hooks.
|
2013-08-06 15:16:03 -04:00
|
|
|
# Check <tt>Rails::Railtie.generators</tt> for more info.
|
2012-06-29 10:50:51 -04:00
|
|
|
def load_generators(app=self)
|
|
|
|
require "rails/generators"
|
|
|
|
run_generators_blocks(app)
|
|
|
|
Rails::Generators.configure!(app.config.generators)
|
|
|
|
self
|
|
|
|
end
|
|
|
|
|
|
|
|
# Eager load the application by loading all ruby
|
2013-02-19 02:22:37 -05:00
|
|
|
# files inside eager_load paths.
|
2012-06-29 10:50:51 -04:00
|
|
|
def eager_load!
|
2013-02-19 02:22:37 -05:00
|
|
|
config.eager_load_paths.each do |load_path|
|
2013-10-29 18:58:52 -04:00
|
|
|
matcher = /\A#{Regexp.escape(load_path.to_s)}\/(.*)\.rb\Z/
|
2010-05-15 17:48:56 -04:00
|
|
|
Dir.glob("#{load_path}/**/*.rb").sort.each do |file|
|
|
|
|
require_dependency file.sub(matcher, '\1')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-12-19 01:54:09 -05:00
|
|
|
def railties
|
2013-02-27 10:11:43 -05:00
|
|
|
@railties ||= Railties.new
|
2012-12-19 01:54:09 -05:00
|
|
|
end
|
|
|
|
|
2012-06-29 10:50:51 -04:00
|
|
|
# Returns a module with all the helpers defined for the engine.
|
2011-04-25 07:12:07 -04:00
|
|
|
def helpers
|
|
|
|
@helpers ||= begin
|
|
|
|
helpers = Module.new
|
2011-04-25 09:02:41 -04:00
|
|
|
all = ActionController::Base.all_helpers_from_path(helpers_paths)
|
|
|
|
ActionController::Base.modules_for_helpers(all).each do |mod|
|
2011-04-25 07:12:07 -04:00
|
|
|
helpers.send(:include, mod)
|
|
|
|
end
|
|
|
|
helpers
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-06-29 10:50:51 -04:00
|
|
|
# Returns all registered helpers paths.
|
2011-11-23 14:06:45 -05:00
|
|
|
def helpers_paths
|
|
|
|
paths["app/helpers"].existent
|
|
|
|
end
|
|
|
|
|
2012-06-29 10:50:51 -04:00
|
|
|
# Returns the underlying rack application for this engine.
|
2010-06-22 17:51:28 -04:00
|
|
|
def app
|
2010-07-05 11:40:35 -04:00
|
|
|
@app ||= begin
|
|
|
|
config.middleware = config.middleware.merge_into(default_middleware_stack)
|
|
|
|
config.middleware.build(endpoint)
|
|
|
|
end
|
2010-06-22 17:51:28 -04:00
|
|
|
end
|
|
|
|
|
2012-06-29 10:50:51 -04:00
|
|
|
# Returns the endpoint for this engine. If none is registered,
|
|
|
|
# defaults to an ActionDispatch::Routing::RouteSet.
|
2010-06-22 17:51:28 -04:00
|
|
|
def endpoint
|
2010-06-24 08:32:11 -04:00
|
|
|
self.class.endpoint || routes
|
2010-06-22 17:51:28 -04:00
|
|
|
end
|
|
|
|
|
2012-06-29 10:50:51 -04:00
|
|
|
# Define the Rack API for this engine.
|
2010-06-22 17:51:28 -04:00
|
|
|
def call(env)
|
2012-08-10 17:27:51 -04:00
|
|
|
env.merge!(env_config)
|
|
|
|
if env['SCRIPT_NAME']
|
|
|
|
env.merge! "ROUTES_#{routes.object_id}_SCRIPT_NAME" => env['SCRIPT_NAME'].dup
|
|
|
|
end
|
|
|
|
app.call(env)
|
2010-07-22 16:11:32 -04:00
|
|
|
end
|
|
|
|
|
2012-06-29 10:50:51 -04:00
|
|
|
# Defines additional Rack env configuration that is added on each call.
|
2010-07-22 16:11:32 -04:00
|
|
|
def env_config
|
|
|
|
@env_config ||= {
|
2011-04-15 13:57:52 -04:00
|
|
|
'action_dispatch.routes' => routes
|
2010-07-22 16:11:32 -04:00
|
|
|
}
|
2010-06-22 17:51:28 -04:00
|
|
|
end
|
|
|
|
|
2012-06-29 10:50:51 -04:00
|
|
|
# Defines the routes for this engine. If a block is given to
|
|
|
|
# routes, it is appended to the engine.
|
2010-10-06 09:54:28 -04:00
|
|
|
def routes
|
2012-06-29 11:39:50 -04:00
|
|
|
@routes ||= ActionDispatch::Routing::RouteSet.new
|
2010-10-06 09:54:28 -04:00
|
|
|
@routes.append(&Proc.new) if block_given?
|
2010-09-25 18:17:06 -04:00
|
|
|
@routes
|
2010-06-24 08:32:11 -04:00
|
|
|
end
|
|
|
|
|
2012-06-29 10:50:51 -04:00
|
|
|
# Define the configuration object for the engine.
|
2010-07-19 11:53:14 -04:00
|
|
|
def config
|
2010-07-29 10:23:15 -04:00
|
|
|
@config ||= Engine::Configuration.new(find_root_with_flag("lib"))
|
2010-07-19 11:53:14 -04:00
|
|
|
end
|
|
|
|
|
2010-09-19 11:21:16 -04:00
|
|
|
# Load data from db/seeds.rb file. It can be used in to load engines'
|
|
|
|
# seeds, e.g.:
|
|
|
|
#
|
|
|
|
# Blog::Engine.load_seed
|
|
|
|
def load_seed
|
2012-04-25 17:43:01 -04:00
|
|
|
seed_file = paths["db/seeds.rb"].existent.first
|
2011-12-14 22:09:31 -05:00
|
|
|
load(seed_file) if seed_file
|
2010-09-19 11:21:16 -04:00
|
|
|
end
|
|
|
|
|
2010-01-21 17:14:20 -05:00
|
|
|
# Add configured load paths to ruby load paths and remove duplicates.
|
2012-10-14 06:03:39 -04:00
|
|
|
initializer :set_load_path, before: :bootstrap_hook do
|
2010-06-27 18:57:47 -04:00
|
|
|
_all_load_paths.reverse_each do |path|
|
2010-01-22 10:24:44 -05:00
|
|
|
$LOAD_PATH.unshift(path) if File.directory?(path)
|
|
|
|
end
|
2010-01-21 17:14:20 -05:00
|
|
|
$LOAD_PATH.uniq!
|
|
|
|
end
|
|
|
|
|
|
|
|
# Set the paths from which Rails will automatically load source files,
|
|
|
|
# and the load_once paths.
|
2010-05-15 09:08:55 -04:00
|
|
|
#
|
|
|
|
# This needs to be an initializer, since it needs to run once
|
|
|
|
# per engine and get the engine as a block parameter
|
2013-04-06 03:50:50 -04:00
|
|
|
initializer :set_autoload_paths, before: :bootstrap_hook do
|
2010-06-27 18:57:47 -04:00
|
|
|
ActiveSupport::Dependencies.autoload_paths.unshift(*_all_autoload_paths)
|
2010-09-03 18:52:07 -04:00
|
|
|
ActiveSupport::Dependencies.autoload_once_paths.unshift(*_all_autoload_once_paths)
|
2010-01-21 17:14:20 -05:00
|
|
|
|
2010-01-22 19:29:29 -05:00
|
|
|
# Freeze so future modifications will fail rather than do nothing mysteriously
|
2010-06-22 17:17:20 -04:00
|
|
|
config.autoload_paths.freeze
|
2013-02-19 02:22:37 -05:00
|
|
|
config.eager_load_paths.freeze
|
2010-06-22 17:17:20 -04:00
|
|
|
config.autoload_once_paths.freeze
|
2010-01-21 17:14:20 -05:00
|
|
|
end
|
|
|
|
|
2010-01-27 11:39:35 -05:00
|
|
|
initializer :add_routing_paths do |app|
|
2012-04-25 17:06:20 -04:00
|
|
|
paths = self.paths["config/routes.rb"].existent
|
2010-10-06 11:18:59 -04:00
|
|
|
|
|
|
|
if routes? || paths.any?
|
|
|
|
app.routes_reloader.paths.unshift(*paths)
|
2010-10-06 09:54:28 -04:00
|
|
|
app.routes_reloader.route_sets << routes
|
2010-01-22 19:29:29 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-01-25 16:00:07 -05:00
|
|
|
# I18n load paths are a special case since the ones added
|
|
|
|
# later have higher priority.
|
2010-01-22 19:29:29 -05:00
|
|
|
initializer :add_locales do
|
2010-10-06 11:18:59 -04:00
|
|
|
config.i18n.railties_load_path.concat(paths["config/locales"].existent)
|
2010-01-21 17:14:20 -05:00
|
|
|
end
|
|
|
|
|
2010-01-21 19:10:31 -05:00
|
|
|
initializer :add_view_paths do
|
2010-10-06 11:18:59 -04:00
|
|
|
views = paths["app/views"].existent
|
2010-09-03 18:52:07 -04:00
|
|
|
unless views.empty?
|
2012-03-15 03:48:38 -04:00
|
|
|
ActiveSupport.on_load(:action_controller){ prepend_view_path(views) if respond_to?(:prepend_view_path) }
|
2010-09-03 18:52:07 -04:00
|
|
|
ActiveSupport.on_load(:action_mailer){ prepend_view_path(views) }
|
2010-03-29 20:08:08 -04:00
|
|
|
end
|
2010-01-21 19:10:31 -05:00
|
|
|
end
|
|
|
|
|
2012-10-14 06:03:39 -04:00
|
|
|
initializer :load_environment_config, before: :load_environment_hook, group: :all do
|
2012-05-16 18:40:57 -04:00
|
|
|
paths["config/environments"].existent.each do |environment|
|
|
|
|
require environment
|
|
|
|
end
|
2010-07-18 17:23:54 -04:00
|
|
|
end
|
|
|
|
|
2012-10-14 06:03:39 -04:00
|
|
|
initializer :append_assets_path, group: :all do |app|
|
2011-08-01 15:32:17 -04:00
|
|
|
app.config.assets.paths.unshift(*paths["vendor/assets"].existent_directories)
|
|
|
|
app.config.assets.paths.unshift(*paths["lib/assets"].existent_directories)
|
|
|
|
app.config.assets.paths.unshift(*paths["app/assets"].existent_directories)
|
2011-04-15 12:42:51 -04:00
|
|
|
end
|
|
|
|
|
2010-10-06 11:18:59 -04:00
|
|
|
initializer :prepend_helpers_path do |app|
|
2010-10-09 14:59:20 -04:00
|
|
|
if !isolated? || (app == self)
|
2010-10-06 11:18:59 -04:00
|
|
|
app.config.helpers_paths.unshift(*paths["app/helpers"].existent)
|
2010-08-23 13:25:04 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-12-13 02:49:04 -05:00
|
|
|
initializer :load_config_initializers do
|
|
|
|
config.paths["config/initializers"].existent.sort.each do |initializer|
|
2013-11-11 12:56:02 -05:00
|
|
|
load_config_initializer(initializer)
|
2011-12-13 02:49:04 -05:00
|
|
|
end
|
2010-09-02 06:09:16 -04:00
|
|
|
end
|
|
|
|
|
2010-09-01 05:07:39 -04:00
|
|
|
initializer :engines_blank_point do
|
|
|
|
# We need this initializer so all extra initializers added in engines are
|
|
|
|
# consistently executed after all the initializers above across all engines.
|
|
|
|
end
|
|
|
|
|
2010-10-09 14:15:45 -04:00
|
|
|
rake_tasks do
|
|
|
|
next if self.is_a?(Rails::Application)
|
2011-04-15 13:57:52 -04:00
|
|
|
next unless has_migrations?
|
2010-10-09 14:15:45 -04:00
|
|
|
|
|
|
|
namespace railtie_name do
|
|
|
|
namespace :install do
|
2011-04-15 13:57:52 -04:00
|
|
|
desc "Copy migrations from #{railtie_name} to application"
|
|
|
|
task :migrations do
|
|
|
|
ENV["FROM"] = railtie_name
|
2012-04-12 10:25:28 -04:00
|
|
|
if Rake::Task.task_defined?("railties:install:migrations")
|
|
|
|
Rake::Task["railties:install:migrations"].invoke
|
|
|
|
else
|
|
|
|
Rake::Task["app:railties:install:migrations"].invoke
|
|
|
|
end
|
2010-10-13 09:20:09 -04:00
|
|
|
end
|
2010-10-10 09:03:57 -04:00
|
|
|
end
|
2010-10-09 14:15:45 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-03-18 22:12:35 -04:00
|
|
|
def routes? #:nodoc:
|
|
|
|
@routes
|
|
|
|
end
|
|
|
|
|
2012-05-22 19:33:08 -04:00
|
|
|
protected
|
2010-12-09 15:18:41 -05:00
|
|
|
|
2013-11-11 12:56:02 -05:00
|
|
|
def load_config_initializer(initializer)
|
|
|
|
ActiveSupport::Notifications.instrument('load_config_initializer.railties', initializer: initializer) do
|
|
|
|
load(initializer)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-06-29 10:50:51 -04:00
|
|
|
def run_tasks_blocks(*) #:nodoc:
|
|
|
|
super
|
|
|
|
paths["lib/tasks"].existent.sort.each { |ext| load(ext) }
|
2011-05-26 11:57:46 -04:00
|
|
|
end
|
|
|
|
|
2012-06-29 10:50:51 -04:00
|
|
|
def has_migrations? #:nodoc:
|
2011-07-02 23:32:58 -04:00
|
|
|
paths["db/migrate"].existent.any?
|
2011-04-15 13:17:58 -04:00
|
|
|
end
|
|
|
|
|
2012-06-29 10:50:51 -04:00
|
|
|
def find_root_with_flag(flag, default=nil) #:nodoc:
|
2010-07-19 11:53:14 -04:00
|
|
|
root_path = self.class.called_from
|
|
|
|
|
|
|
|
while root_path && File.directory?(root_path) && !File.exist?("#{root_path}/#{flag}")
|
|
|
|
parent = File.dirname(root_path)
|
|
|
|
root_path = parent != root_path && parent
|
|
|
|
end
|
|
|
|
|
|
|
|
root = File.exist?("#{root_path}/#{flag}") ? root_path : default
|
|
|
|
raise "Could not find root path for #{self}" unless root
|
|
|
|
|
2012-05-24 00:29:08 -04:00
|
|
|
Pathname.new File.realpath root
|
2010-07-19 11:53:14 -04:00
|
|
|
end
|
|
|
|
|
2012-06-29 10:50:51 -04:00
|
|
|
def default_middleware_stack #:nodoc:
|
2010-07-08 06:07:25 -04:00
|
|
|
ActionDispatch::MiddlewareStack.new
|
|
|
|
end
|
2010-01-23 12:41:53 -05:00
|
|
|
|
2012-06-29 10:50:51 -04:00
|
|
|
def _all_autoload_once_paths #:nodoc:
|
2010-09-03 18:52:07 -04:00
|
|
|
config.autoload_once_paths
|
|
|
|
end
|
|
|
|
|
2012-06-29 10:50:51 -04:00
|
|
|
def _all_autoload_paths #:nodoc:
|
2013-02-19 02:22:37 -05:00
|
|
|
@_all_autoload_paths ||= (config.autoload_paths + config.eager_load_paths + config.autoload_once_paths).uniq
|
2010-06-27 18:57:47 -04:00
|
|
|
end
|
|
|
|
|
2012-06-29 10:50:51 -04:00
|
|
|
def _all_load_paths #:nodoc:
|
2010-06-27 18:57:47 -04:00
|
|
|
@_all_load_paths ||= (config.paths.load_paths + _all_autoload_paths).uniq
|
2010-01-23 12:41:53 -05:00
|
|
|
end
|
2010-01-21 17:14:20 -05:00
|
|
|
end
|
2010-02-26 16:29:44 -05:00
|
|
|
end
|