Permalink
Browse files

Remove Rails::ApiApplication, just configure Rails::Application

  • Loading branch information...
1 parent 51008d4 commit cf2364ac186c85385ae693812b0001ece1fb54eb @spastorino spastorino committed Apr 20, 2012
@@ -1,5 +1,5 @@
-require 'action_controller/log_subscriber'
require 'action_controller'
+require 'action_controller/log_subscriber'
module ActionController
# API Controller is a lightweight version of <tt>ActionController::Base</tt>,
@@ -1,10 +1,8 @@
-require 'rails/engine'
-require 'rails-api/monkey_patches/application'
+require 'rails/version'
+require 'rails/application'
module Rails
- class ApiApplication < Engine
- include Base
-
+ class Application < Engine
def default_middleware_stack
ActionDispatch::MiddlewareStack.new.tap do |middleware|
if rack_cache = config.action_controller.perform_caching && config.action_dispatch.rack_cache
@@ -46,7 +44,7 @@ def default_middleware_stack
end
end
- if Rails.version <= "3.2.3"
+ if Rails::VERSION::STRING <= "3.2.3"
def load_generators(app=self)
super
require 'rails/generators/rails/resource/resource_generator'
@@ -70,7 +68,7 @@ def setup_generators!
generators = config.generators
generators.templates.unshift File::expand_path('../templates', __FILE__)
- if Rails.version > "3.2.3"
+ if Rails::VERSION::STRING > "3.2.3"
generators.resource_route = :api_resource_route
end
@@ -1,210 +0,0 @@
-require 'fileutils'
-
-module Rails
- class Railtie
- remove_const :ABSTRACT_RAILTIES
- ABSTRACT_RAILTIES = %w(Rails::Railtie Rails::Engine Rails::Application Rails::ApiApplication)
- end
-
- module Base
- Bootstrap = ::Rails::Application::Bootstrap
- Configuration = ::Rails::Application::Configuration
- Finisher = ::Rails::Application::Finisher
- Railties = ::Rails::Application::Railties
- RoutesReloader = ::Rails::Application::RoutesReloader
-
- module ClassMethods
- def inherited(base)
- raise "You cannot have more than one Rails::Application" if Rails.application
- super
- Rails.application = base.instance
- Rails.application.add_lib_to_load_path!
- ActiveSupport.run_load_hooks(:before_configuration, base.instance)
- end
- end
-
- def self.included(base)
- base.extend ClassMethods
-
- base.class_eval do
- alias_method :build_middleware_stack, :app
- end
- end
-
- attr_accessor :assets, :sandbox
- alias_method :sandbox?, :sandbox
- attr_reader :reloaders
-
- delegate :default_url_options, :default_url_options=, :to => :routes
-
- def initialize
- super
- @initialized = false
- @reloaders = []
- end
-
- # This method is called just after an application inherits from Rails::Application,
- # allowing the developer to load classes in lib and use them during application
- # configuration.
- #
- # class MyApplication < Rails::Application
- # require "my_backend" # in lib/my_backend
- # config.i18n.backend = MyBackend
- # end
- #
- # Notice this method takes into consideration the default root path. So if you
- # are changing config.root inside your application definition or having a custom
- # Rails application, you will need to add lib to $LOAD_PATH on your own in case
- # you need to load files in lib/ during the application configuration as well.
- def add_lib_to_load_path! #:nodoc:
- path = config.root.join('lib').to_s
- $LOAD_PATH.unshift(path) if File.exists?(path)
- end
-
- def require_environment! #:nodoc:
- environment = paths["config/environment"].existent.first
- require environment if environment
- end
-
- # Reload application routes regardless if they changed or not.
- def reload_routes!
- routes_reloader.reload!
- end
-
- def routes_reloader #:nodoc:
- @routes_reloader ||= Application::RoutesReloader.new
- end
-
- # Returns an array of file paths appended with a hash of directories-extensions
- # suitable for ActiveSupport::FileUpdateChecker API.
- def watchable_args
- files, dirs = config.watchable_files.dup, config.watchable_dirs.dup
-
- ActiveSupport::Dependencies.autoload_paths.each do |path|
- dirs[path.to_s] = [:rb]
- end
-
- [files, dirs]
- end
-
- # Initialize the application passing the given group. By default, the
- # group is :default but sprockets precompilation passes group equals
- # to assets if initialize_on_precompile is false to avoid booting the
- # whole app.
- def initialize!(group=:default) #:nodoc:
- raise "Application has been already initialized." if @initialized
- run_initializers(group, self)
- @initialized = true
- self
- end
-
- # Load the application and its railties tasks and invoke the registered hooks.
- # Check <tt>Rails::Railtie.rake_tasks</tt> for more info.
- def load_tasks(app=self)
- initialize_tasks
- super
- self
- end
-
- # Load the application console and invoke the registered hooks.
- # Check <tt>Rails::Railtie.console</tt> for more info.
- def load_console(app=self)
- initialize_console
- super
- self
- end
-
- # Stores some of the Rails initial environment parameters which
- # will be used by middlewares and engines to configure themselves.
- def env_config
- @env_config ||= super.merge({
- "action_dispatch.parameter_filter" => config.filter_parameters,
- "action_dispatch.secret_token" => config.secret_token,
- "action_dispatch.show_exceptions" => config.action_dispatch.show_exceptions,
- "action_dispatch.show_detailed_exceptions" => config.consider_all_requests_local,
- "action_dispatch.logger" => Rails.logger,
- "action_dispatch.backtrace_cleaner" => Rails.backtrace_cleaner
- })
- end
-
- # Returns the ordered railties for this application considering railties_order.
- def ordered_railties #:nodoc:
- @ordered_railties ||= begin
- order = config.railties_order.map do |railtie|
- if railtie == :main_app
- self
- elsif railtie.respond_to?(:instance)
- railtie.instance
- else
- railtie
- end
- end
-
- all = (railties.all - order)
- all.push(self) unless all.include?(self)
- order.push(:all) unless order.include?(:all)
-
- index = order.index(:all)
- order[index] = all
- order.reverse.flatten
- end
- end
-
- def initializers #:nodoc:
- Application::Bootstrap.initializers_for(self) +
- super +
- Application::Finisher.initializers_for(self)
- end
-
- def config #:nodoc:
- @config ||= Application::Configuration.new(find_root_with_flag("config.ru", Dir.pwd))
- end
-
- def to_app
- self
- end
-
- def helpers_paths #:nodoc:
- config.helpers_paths
- end
-
- def call(env)
- env["ORIGINAL_FULLPATH"] = build_original_fullpath(env)
- super(env)
- end
-
- protected
-
- def reload_dependencies?
- config.reload_classes_only_on_change != true || reloaders.map(&:updated?).any?
- end
-
- def initialize_tasks #:nodoc:
- self.class.rake_tasks do
- require "rails/tasks"
- task :environment do
- $rails_rake_task = true
- require_environment!
- end
- end
- end
-
- def initialize_console #:nodoc:
- require "pp"
- require "rails/console/app"
- require "rails/console/helpers"
- end
-
- def build_original_fullpath(env)
- path_info = env["PATH_INFO"]
- query_string = env["QUERY_STRING"]
- script_name = env["SCRIPT_NAME"]
-
- if query_string.present?
- "#{script_name}#{path_info}?#{query_string}"
- else
- "#{script_name}#{path_info}"
- end
- end
- end
-end
@@ -1,78 +0,0 @@
-require File.expand_path('../boot', __FILE__)
-
-<% if include_all_railties? -%>
-require 'rails/all'
-<% else -%>
-# Pick the frameworks you want:
-<%= comment_if :skip_active_record %>require "active_record/railtie"
-require "action_controller/railtie"
-require "action_mailer/railtie"
-require "active_resource/railtie" if Rails.version < "4.0.0"
-if Rails.version < "4.0.0"
-<%= comment_if :skip_sprockets %>require "sprockets/railtie"
-else
-<%= comment_if :skip_sprockets %>require "sprockets/rails/railtie"
-end
-<%= comment_if :skip_test_unit %>require "rails/test_unit/railtie"
-<% end -%>
-
-if defined?(Bundler)
- # If you precompile assets before deploying to production, use this line.
- Bundler.require(*Rails.groups(:assets => %w(development test)))
- # If you want your assets lazily compiled in production, use this line.
- # Bundler.require(:default, :assets, Rails.env)
-end
-
-module <%= app_const_base %>
- class Application < Rails::ApiApplication
- # Settings in config/environments/* take precedence over those specified here.
- # Application configuration should go into files in config/initializers
- # -- all .rb files in that directory are automatically loaded.
-
- # Custom directories with classes and modules you want to be autoloadable.
- # config.autoload_paths += %W(#{config.root}/extras)
-
- # Activate observers that should always be running.
- # config.active_record.observers = :cacher, :garbage_collector, :forum_observer
-
- # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
- # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
- # config.time_zone = 'Central Time (US & Canada)'
-
- # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
- # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
- # config.i18n.default_locale = :de
-
- # Configure the default encoding used in templates for Ruby 1.9.
- config.encoding = "utf-8"
-
- # Configure sensitive parameters which will be filtered from the log file.
- config.filter_parameters += [:password]
-
- # Use SQL instead of Active Record's schema dumper when creating the database.
- # This is necessary if your schema can't be completely dumped by the schema dumper,
- # like if you have constraints or database-specific column types.
- # config.active_record.schema_format = :sql
-
- # Enforce whitelist mode for mass assignment.
- # This will create an empty whitelist of attributes available for mass-assignment for all models
- # in your app. As such, your models will need to explicitly whitelist or blacklist accessible
- # parameters by using an attr_accessible or attr_protected declaration.
- <%= comment_if :skip_active_record %>config.active_record.whitelist_attributes = true
-
- # Specifies wether or not has_many or has_one association option :dependent => :restrict raises
- # an exception. If set to true, then an ActiveRecord::DeleteRestrictionError exception would be
- # raised. If set to false, then an error will be added on the model instead.
- if Rails.version >= "4.0.0"
- <%= comment_if :skip_active_record %>config.active_record.dependent_restrict_raises = false
- end
-<% unless options.skip_sprockets? -%>
-
- # Enable the asset pipeline.
- config.assets.enabled = true
-
- # Version of your assets, change this if you want to expire all your assets.
- config.assets.version = '1.0'
-<% end -%>
- end
-end
@@ -21,7 +21,6 @@ def test_api_modified_files
assert_no_match(/gem 'sass-rails'/, content)
end
assert_file "app/controllers/application_controller.rb", /ActionController::API/
- assert_file "config/application.rb", /Rails::ApiApplication/
end
private
View
@@ -6,7 +6,7 @@
require 'rails-api'
def app
- @@app ||= Class.new(Rails::ApiApplication) do
+ @@app ||= Class.new(Rails::Application) do
config.active_support.deprecation = :stderr
config.generators do |c|
c.orm :active_record, :migration => true,
@@ -18,6 +18,10 @@ def app
c.integration_tool :test_unit
c.performance_tool :test_unit
end
+
+ def self.name
+ 'TestApp'
+ end
end
end

0 comments on commit cf2364a

Please sign in to comment.