aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEmilio Tagua <miloops@gmail.com>2009-05-09 13:07:30 -0300
committerEmilio Tagua <miloops@gmail.com>2009-05-09 13:07:30 -0300
commit6c7d8cb8ac9e6b6775e9a54ef0be62dbaab592f5 (patch)
treec169325ddd18aedd18c66f22a53ba04190a0a41e
parent8885b2d6c1855742600d0afdb9dfc002acb62e5e (diff)
parent8ee0c598dbe3f9fd133e85c69c6e43f62056646c (diff)
downloadrails-6c7d8cb8ac9e6b6775e9a54ef0be62dbaab592f5.tar.gz
rails-6c7d8cb8ac9e6b6775e9a54ef0be62dbaab592f5.tar.bz2
rails-6c7d8cb8ac9e6b6775e9a54ef0be62dbaab592f5.zip
Merge commit 'rails/master'
-rw-r--r--actionpack/lib/action_controller/abstract.rb2
-rw-r--r--actionpack/lib/action_controller/abstract/base.rb19
-rw-r--r--actionpack/lib/action_controller/abstract/callbacks.rb19
-rw-r--r--actionpack/lib/action_controller/abstract/exceptions.rb2
-rw-r--r--actionpack/lib/action_controller/abstract/helpers.rb23
-rw-r--r--actionpack/lib/action_controller/abstract/layouts.rb32
-rw-r--r--actionpack/lib/action_controller/abstract/logger.rb6
-rw-r--r--actionpack/lib/action_controller/abstract/renderer.rb31
-rw-r--r--actionpack/lib/action_controller/new_base.rb2
-rw-r--r--actionpack/lib/action_controller/new_base/base.rb27
-rw-r--r--actionpack/lib/action_controller/new_base/hide_actions.rb17
-rw-r--r--actionpack/lib/action_controller/new_base/layouts.rb16
-rw-r--r--actionpack/lib/action_controller/new_base/renderer.rb25
-rw-r--r--actionpack/lib/action_controller/new_base/url_for.rb6
-rw-r--r--actionpack/test/abstract_controller/callbacks_test.rb2
-rw-r--r--actionpack/test/abstract_controller/layouts_test.rb6
-rw-r--r--actionpack/test/new_base/test_helper.rb14
-rw-r--r--activeresource/lib/active_resource/base.rb1
-rw-r--r--activeresource/test/base/load_test.rb1
-rw-r--r--activesupport/lib/active_support.rb1
-rw-r--r--activesupport/lib/active_support/core_ext/module.rb1
-rw-r--r--activesupport/lib/active_support/core_ext/module/setup.rb26
-rw-r--r--activesupport/lib/active_support/dependency_module.rb24
-rw-r--r--activesupport/test/dependency_module_test.rb77
-rw-r--r--railties/lib/initializer.rb2
-rw-r--r--railties/lib/tasks/gems.rake3
-rw-r--r--tools/profile_requires.rb75
27 files changed, 307 insertions, 153 deletions
diff --git a/actionpack/lib/action_controller/abstract.rb b/actionpack/lib/action_controller/abstract.rb
index 3f5c4a185f..9442d4559f 100644
--- a/actionpack/lib/action_controller/abstract.rb
+++ b/actionpack/lib/action_controller/abstract.rb
@@ -7,4 +7,4 @@ module AbstractController
autoload :Renderer, "action_controller/abstract/renderer"
# === Exceptions
autoload :ActionNotFound, "action_controller/abstract/exceptions"
-end \ No newline at end of file
+end
diff --git a/actionpack/lib/action_controller/abstract/base.rb b/actionpack/lib/action_controller/abstract/base.rb
index ade7719cc0..39e9ad0440 100644
--- a/actionpack/lib/action_controller/abstract/base.rb
+++ b/actionpack/lib/action_controller/abstract/base.rb
@@ -1,41 +1,38 @@
module AbstractController
class Base
-
attr_internal :response_body
attr_internal :response_obj
attr_internal :action_name
-
+
def self.process(action)
new.process(action)
end
-
+
def self.inherited(klass)
end
-
+
def initialize
self.response_obj = {}
end
-
+
def process(action_name)
unless respond_to_action?(action_name)
raise ActionNotFound, "The action '#{action_name}' could not be found"
end
-
+
@_action_name = action_name
process_action
self.response_obj[:body] = self.response_body
self
end
-
+
private
-
def process_action
respond_to?(action_name) ? send(action_name) : send(:action_missing, action_name)
end
-
+
def respond_to_action?(action_name)
respond_to?(action_name) || respond_to?(:action_missing, true)
end
-
end
-end \ No newline at end of file
+end
diff --git a/actionpack/lib/action_controller/abstract/callbacks.rb b/actionpack/lib/action_controller/abstract/callbacks.rb
index c8b509081c..cb8aade0be 100644
--- a/actionpack/lib/action_controller/abstract/callbacks.rb
+++ b/actionpack/lib/action_controller/abstract/callbacks.rb
@@ -1,16 +1,19 @@
module AbstractController
module Callbacks
- setup do
- include ActiveSupport::NewCallbacks
- define_callbacks :process_action
+ extend ActiveSupport::DependencyModule
+
+ depends_on ActiveSupport::NewCallbacks
+
+ included do
+ define_callbacks :process_action
end
-
+
def process_action
_run_process_action_callbacks(action_name) do
super
end
end
-
+
module ClassMethods
def _normalize_callback_options(options)
if only = options[:only]
@@ -18,11 +21,11 @@ module AbstractController
options[:per_key] = {:if => only}
end
if except = options[:except]
- except = Array(except).map {|e| "action_name == :#{e}"}.join(" || ")
+ except = Array(except).map {|e| "action_name == :#{e}"}.join(" || ")
options[:per_key] = {:unless => except}
end
end
-
+
[:before, :after, :around].each do |filter|
class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1
def #{filter}_filter(*names, &blk)
@@ -37,4 +40,4 @@ module AbstractController
end
end
end
-end \ No newline at end of file
+end
diff --git a/actionpack/lib/action_controller/abstract/exceptions.rb b/actionpack/lib/action_controller/abstract/exceptions.rb
index ec4680629b..a7d07868bb 100644
--- a/actionpack/lib/action_controller/abstract/exceptions.rb
+++ b/actionpack/lib/action_controller/abstract/exceptions.rb
@@ -1,3 +1,3 @@
module AbstractController
class ActionNotFound < StandardError ; end
-end \ No newline at end of file
+end
diff --git a/actionpack/lib/action_controller/abstract/helpers.rb b/actionpack/lib/action_controller/abstract/helpers.rb
index 1f0b38417b..38e3ce8127 100644
--- a/actionpack/lib/action_controller/abstract/helpers.rb
+++ b/actionpack/lib/action_controller/abstract/helpers.rb
@@ -1,19 +1,21 @@
module AbstractController
module Helpers
+ extend ActiveSupport::DependencyModule
+
depends_on Renderer
-
- setup do
+
+ included do
extlib_inheritable_accessor :master_helper_module
self.master_helper_module = Module.new
end
-
+
# def self.included(klass)
# klass.class_eval do
# extlib_inheritable_accessor :master_helper_module
# self.master_helper_module = Module.new
# end
# end
-
+
def _action_view
@_action_view ||= begin
av = super
@@ -21,19 +23,19 @@ module AbstractController
av
end
end
-
+
module ClassMethods
def inherited(klass)
klass.master_helper_module = Module.new
klass.master_helper_module.__send__ :include, master_helper_module
-
+
super
end
-
+
def add_template_helper(mod)
master_helper_module.module_eval { include mod }
end
-
+
def helper_method(*meths)
meths.flatten.each do |meth|
master_helper_module.class_eval <<-ruby_eval, __FILE__, __LINE__ + 1
@@ -43,7 +45,7 @@ module AbstractController
ruby_eval
end
end
-
+
def helper(*args, &blk)
args.flatten.each do |arg|
case arg
@@ -54,6 +56,5 @@ module AbstractController
master_helper_module.module_eval(&blk) if block_given?
end
end
-
end
-end \ No newline at end of file
+end
diff --git a/actionpack/lib/action_controller/abstract/layouts.rb b/actionpack/lib/action_controller/abstract/layouts.rb
index 0039e67c5a..69fe4efc19 100644
--- a/actionpack/lib/action_controller/abstract/layouts.rb
+++ b/actionpack/lib/action_controller/abstract/layouts.rb
@@ -1,25 +1,26 @@
module AbstractController
module Layouts
-
+ extend ActiveSupport::DependencyModule
+
depends_on Renderer
-
+
module ClassMethods
def layout(layout)
unless [String, Symbol, FalseClass, NilClass].include?(layout.class)
raise ArgumentError, "Layouts must be specified as a String, Symbol, false, or nil"
end
-
+
@_layout = layout || false # Converts nil to false
_write_layout_method
end
-
+
def _implied_layout_name
name.underscore
end
-
+
# Takes the specified layout and creates a _layout method to be called
# by _default_layout
- #
+ #
# If the specified layout is a:
# String:: return the string
# Symbol:: call the method specified by the symbol
@@ -48,35 +49,34 @@ module AbstractController
end
end
end
-
+
def _render_template(template, options)
_action_view._render_template_with_layout(template, options[:_layout])
end
-
+
private
-
def _layout() end # This will be overwritten
-
+
def _layout_for_name(name)
unless [String, FalseClass, NilClass].include?(name.class)
raise ArgumentError, "String, false, or nil expected; you passed #{name.inspect}"
end
-
+
name && view_paths.find_by_parts(name, {:formats => formats}, "layouts")
end
-
+
def _default_layout(require_layout = false)
if require_layout && !_layout
- raise ArgumentError,
+ raise ArgumentError,
"There was no default layout for #{self.class} in #{view_paths.inspect}"
end
-
+
begin
layout = _layout_for_name(_layout)
rescue NameError => e
- raise NoMethodError,
+ raise NoMethodError,
"You specified #{@_layout.inspect} as the layout, but no such method was found"
end
end
end
-end \ No newline at end of file
+end
diff --git a/actionpack/lib/action_controller/abstract/logger.rb b/actionpack/lib/action_controller/abstract/logger.rb
index 4117369bd4..c3bccd7778 100644
--- a/actionpack/lib/action_controller/abstract/logger.rb
+++ b/actionpack/lib/action_controller/abstract/logger.rb
@@ -1,7 +1,9 @@
module AbstractController
module Logger
- setup do
+ extend ActiveSupport::DependencyModule
+
+ included do
cattr_accessor :logger
end
end
-end \ No newline at end of file
+end
diff --git a/actionpack/lib/action_controller/abstract/renderer.rb b/actionpack/lib/action_controller/abstract/renderer.rb
index e31accbbfc..b5c31a27ee 100644
--- a/actionpack/lib/action_controller/abstract/renderer.rb
+++ b/actionpack/lib/action_controller/abstract/renderer.rb
@@ -2,33 +2,35 @@ require "action_controller/abstract/logger"
module AbstractController
module Renderer
+ extend ActiveSupport::DependencyModule
+
depends_on AbstractController::Logger
-
- setup do
+
+ included do
attr_internal :formats
-
+
extlib_inheritable_accessor :_view_paths
-
+
self._view_paths ||= ActionView::PathSet.new
end
-
+
def _action_view
- @_action_view ||= ActionView::Base.new(self.class.view_paths, {}, self)
+ @_action_view ||= ActionView::Base.new(self.class.view_paths, {}, self)
end
-
+
def render(options = {})
self.response_body = render_to_body(options)
end
-
+
# Raw rendering of a template to a Rack-compatible body.
# ====
# @option _prefix<String> The template's path prefix
# @option _layout<String> The relative path to the layout template to use
- #
+ #
# :api: plugin
def render_to_body(options = {})
name = options[:_template_name] || action_name
-
+
template = options[:_template] || view_paths.find_by_parts(name.to_s, {:formats => formats}, options[:_prefix])
_render_template(template, options)
end
@@ -37,7 +39,7 @@ module AbstractController
# ====
# @option _prefix<String> The template's path prefix
# @option _layout<String> The relative path to the layout template to use
- #
+ #
# :api: plugin
def render_to_string(options = {})
AbstractController::Renderer.body_to_s(render_to_body(options))
@@ -46,7 +48,7 @@ module AbstractController
def _render_template(template, options)
_action_view._render_template_with_layout(template)
end
-
+
def view_paths() _view_paths end
# Return a string representation of a Rack-compatible response body.
@@ -62,15 +64,14 @@ module AbstractController
end
module ClassMethods
-
def append_view_path(path)
self.view_paths << path
end
-
+
def view_paths
self._view_paths
end
-
+
def view_paths=(paths)
self._view_paths = paths.is_a?(ActionView::PathSet) ?
paths : ActionView::Base.process_view_paths(paths)
diff --git a/actionpack/lib/action_controller/new_base.rb b/actionpack/lib/action_controller/new_base.rb
index 7c65f1cdc1..29dc3aaddc 100644
--- a/actionpack/lib/action_controller/new_base.rb
+++ b/actionpack/lib/action_controller/new_base.rb
@@ -4,4 +4,4 @@ module ActionController
autoload :Layouts, "action_controller/new_base/layouts"
autoload :Renderer, "action_controller/new_base/renderer"
autoload :UrlFor, "action_controller/new_base/url_for"
-end \ No newline at end of file
+end
diff --git a/actionpack/lib/action_controller/new_base/base.rb b/actionpack/lib/action_controller/new_base/base.rb
index 08e7a1a0e7..2dd5390c99 100644
--- a/actionpack/lib/action_controller/new_base/base.rb
+++ b/actionpack/lib/action_controller/new_base/base.rb
@@ -1,6 +1,5 @@
module ActionController
class AbstractBase < AbstractController::Base
-
# :api: public
attr_internal :request, :response, :params
@@ -12,46 +11,46 @@ module ActionController
# :api: public
def controller_name() self.class.controller_name end
- # :api: public
+ # :api: public
def self.controller_path
@controller_path ||= self.name.sub(/Controller$/, '').underscore
end
-
- # :api: public
+
+ # :api: public
def controller_path() self.class.controller_path end
-
- # :api: private
+
+ # :api: private
def self.action_methods
@action_names ||= Set.new(self.public_instance_methods - self::CORE_METHODS)
end
-
- # :api: private
+
+ # :api: private
def self.action_names() action_methods end
-
- # :api: private
+
+ # :api: private
def action_methods() self.class.action_names end
# :api: private
def action_names() action_methods end
-
+
# :api: plugin
def self.call(env)
controller = new
controller.call(env).to_rack
end
-
+
# :api: plugin
def response_body=(body)
@_response.body = body
end
-
+
# :api: private
def call(env)
@_request = ActionDispatch::Request.new(env)
@_response = ActionDispatch::Response.new
process(@_request.parameters[:action])
end
-
+
# :api: private
def to_rack
response.to_a
diff --git a/actionpack/lib/action_controller/new_base/hide_actions.rb b/actionpack/lib/action_controller/new_base/hide_actions.rb
index 473a8ea72b..422ea180c4 100644
--- a/actionpack/lib/action_controller/new_base/hide_actions.rb
+++ b/actionpack/lib/action_controller/new_base/hide_actions.rb
@@ -1,26 +1,25 @@
module ActionController
module HideActions
- setup do
+ included do
extlib_inheritable_accessor :hidden_actions
- self.hidden_actions ||= Set.new
+ self.hidden_actions ||= Set.new
end
-
+
def action_methods() self.class.action_names end
- def action_names() action_methods end
-
+ def action_names() action_methods end
+
private
-
def respond_to_action?(action_name)
!hidden_actions.include?(action_name) && (super || respond_to?(:method_missing))
end
-
+
module ClassMethods
def hide_action(*args)
args.each do |arg|
self.hidden_actions << arg.to_s
end
end
-
+
def action_methods
@action_names ||= Set.new(super.reject {|name| self.hidden_actions.include?(name.to_s)})
end
@@ -28,4 +27,4 @@ module ActionController
def self.action_names() action_methods end
end
end
-end \ No newline at end of file
+end
diff --git a/actionpack/lib/action_controller/new_base/layouts.rb b/actionpack/lib/action_controller/new_base/layouts.rb
index a8e0809ac6..228162421d 100644
--- a/actionpack/lib/action_controller/new_base/layouts.rb
+++ b/actionpack/lib/action_controller/new_base/layouts.rb
@@ -1,14 +1,16 @@
module ActionController
module Layouts
+ extend ActiveSupport::DependencyModule
+
depends_on ActionController::Renderer
depends_on AbstractController::Layouts
-
+
module ClassMethods
def _implied_layout_name
controller_path
end
end
-
+
def render_to_body(options)
# render :text => ..., :layout => ...
# or
@@ -16,22 +18,20 @@ module ActionController
if !options.key?(:text) || options.key?(:layout)
options[:_layout] = options.key?(:layout) ? _layout_for_option(options[:layout]) : _default_layout
end
-
+
super
end
-
+
private
-
def _layout_for_option(name)
case name
when String then _layout_for_name(name)
when true then _default_layout(true)
when false, nil then nil
else
- raise ArgumentError,
- "String, true, or false, expected for `layout'; you passed #{name.inspect}"
+ raise ArgumentError,
+ "String, true, or false, expected for `layout'; you passed #{name.inspect}"
end
end
-
end
end
diff --git a/actionpack/lib/action_controller/new_base/renderer.rb b/actionpack/lib/action_controller/new_base/renderer.rb
index ed34c46aed..d7ea9ec4a5 100644
--- a/actionpack/lib/action_controller/new_base/renderer.rb
+++ b/actionpack/lib/action_controller/new_base/renderer.rb
@@ -1,22 +1,24 @@
module ActionController
module Renderer
+ extend ActiveSupport::DependencyModule
+
depends_on AbstractController::Renderer
-
+
def initialize(*)
self.formats = [:html]
super
end
-
+
def render(action, options = {})
# TODO: Move this into #render_to_body
if action.is_a?(Hash)
- options, action = action, nil
+ options, action = action, nil
else
options.merge! :action => action
end
-
+
_process_options(options)
-
+
self.response_body = render_to_body(options)
end
@@ -32,18 +34,17 @@ module ActionController
options[:_template_name] = options[:template]
elsif options.key?(:action)
options[:_template_name] = options[:action].to_s
- options[:_prefix] = _prefix
+ options[:_prefix] = _prefix
end
-
+
super(options)
end
-
+
private
-
def _prefix
controller_path
- end
-
+ end
+
def _text(options)
text = options[:text]
@@ -52,7 +53,7 @@ module ActionController
else text.to_s
end
end
-
+
def _process_options(options)
if status = options[:status]
response.status = status.to_i
diff --git a/actionpack/lib/action_controller/new_base/url_for.rb b/actionpack/lib/action_controller/new_base/url_for.rb
index af5b21012b..3179c8cd5b 100644
--- a/actionpack/lib/action_controller/new_base/url_for.rb
+++ b/actionpack/lib/action_controller/new_base/url_for.rb
@@ -16,7 +16,7 @@ module ActionController
# by this method.
def default_url_options(options = nil)
end
-
+
def rewrite_options(options) #:nodoc:
if defaults = default_url_options(options)
defaults.merge(options)
@@ -24,7 +24,7 @@ module ActionController
options
end
end
-
+
def url_for(options = {})
options ||= {}
case options
@@ -37,4 +37,4 @@ module ActionController
end
end
end
-end \ No newline at end of file
+end
diff --git a/actionpack/test/abstract_controller/callbacks_test.rb b/actionpack/test/abstract_controller/callbacks_test.rb
index 5fce30f478..89243b631e 100644
--- a/actionpack/test/abstract_controller/callbacks_test.rb
+++ b/actionpack/test/abstract_controller/callbacks_test.rb
@@ -4,7 +4,7 @@ module AbstractController
module Testing
class ControllerWithCallbacks < AbstractController::Base
- use AbstractController::Callbacks
+ include AbstractController::Callbacks
end
class Callback1 < ControllerWithCallbacks
diff --git a/actionpack/test/abstract_controller/layouts_test.rb b/actionpack/test/abstract_controller/layouts_test.rb
index 3d4570bfef..a305a30a54 100644
--- a/actionpack/test/abstract_controller/layouts_test.rb
+++ b/actionpack/test/abstract_controller/layouts_test.rb
@@ -5,9 +5,9 @@ module AbstractControllerTests
# Base controller for these tests
class Base < AbstractController::Base
- use AbstractController::Renderer
- use AbstractController::Layouts
-
+ include AbstractController::Renderer
+ include AbstractController::Layouts
+
self.view_paths = [ActionView::FixtureTemplate::FixturePath.new(
"layouts/hello.erb" => "With String <%= yield %>",
"layouts/hello_override.erb" => "With Override <%= yield %>",
diff --git a/actionpack/test/new_base/test_helper.rb b/actionpack/test/new_base/test_helper.rb
index d29449ddc1..89c29d9af3 100644
--- a/actionpack/test/new_base/test_helper.rb
+++ b/actionpack/test/new_base/test_helper.rb
@@ -26,14 +26,14 @@ require 'rack/test'
module ActionController
class Base2 < AbstractBase
- use AbstractController::Callbacks
- use AbstractController::Helpers
- use AbstractController::Logger
+ include AbstractController::Callbacks
+ include AbstractController::Helpers
+ include AbstractController::Logger
- use ActionController::HideActions
- use ActionController::UrlFor
- use ActionController::Renderer
- use ActionController::Layouts
+ include ActionController::HideActions
+ include ActionController::UrlFor
+ include ActionController::Renderer
+ include ActionController::Layouts
def self.inherited(klass)
::ActionController::Base2.subclasses << klass.to_s
diff --git a/activeresource/lib/active_resource/base.rb b/activeresource/lib/active_resource/base.rb
index be022f5c44..8a1236c9a8 100644
--- a/activeresource/lib/active_resource/base.rb
+++ b/activeresource/lib/active_resource/base.rb
@@ -3,6 +3,7 @@ require 'active_support/core_ext/class/inheritable_attributes'
require 'active_support/core_ext/module/attr_accessor_with_default'
require 'active_support/core_ext/module/delegation'
require 'active_support/core_ext/module/aliasing'
+require 'active_support/core_ext/object/misc'
require 'set'
module ActiveResource
diff --git a/activeresource/test/base/load_test.rb b/activeresource/test/base/load_test.rb
index a475fab34e..cd2103acb7 100644
--- a/activeresource/test/base/load_test.rb
+++ b/activeresource/test/base/load_test.rb
@@ -1,6 +1,7 @@
require 'abstract_unit'
require "fixtures/person"
require "fixtures/street_address"
+require 'active_support/core_ext/symbol'
module Highrise
class Note < ActiveResource::Base
diff --git a/activesupport/lib/active_support.rb b/activesupport/lib/active_support.rb
index 0879535487..dab017770d 100644
--- a/activesupport/lib/active_support.rb
+++ b/activesupport/lib/active_support.rb
@@ -34,6 +34,7 @@ module ActiveSupport
autoload :Callbacks, 'active_support/callbacks'
autoload :NewCallbacks, 'active_support/new_callbacks'
autoload :ConcurrentHash, 'active_support/concurrent_hash'
+ autoload :DependencyModule, 'active_support/dependency_module'
autoload :Deprecation, 'active_support/deprecation'
autoload :Gzip, 'active_support/gzip'
autoload :Inflector, 'active_support/inflector'
diff --git a/activesupport/lib/active_support/core_ext/module.rb b/activesupport/lib/active_support/core_ext/module.rb
index fee91534e7..215c47b114 100644
--- a/activesupport/lib/active_support/core_ext/module.rb
+++ b/activesupport/lib/active_support/core_ext/module.rb
@@ -9,4 +9,3 @@ require 'active_support/core_ext/module/delegation'
require 'active_support/core_ext/module/loading'
require 'active_support/core_ext/module/model_naming'
require 'active_support/core_ext/module/synchronization'
-require 'active_support/core_ext/module/setup'
diff --git a/activesupport/lib/active_support/core_ext/module/setup.rb b/activesupport/lib/active_support/core_ext/module/setup.rb
deleted file mode 100644
index e6dfd0cf56..0000000000
--- a/activesupport/lib/active_support/core_ext/module/setup.rb
+++ /dev/null
@@ -1,26 +0,0 @@
-class Module
- attr_accessor :_setup_block
- attr_accessor :_dependencies
-
- def setup(&blk)
- @_setup_block = blk
- end
-
- def use(mod)
- return if self < mod
-
- (mod._dependencies || []).each do |dep|
- use dep
- end
- # raise "Circular dependencies" if self < mod
- include mod
- extend mod.const_get("ClassMethods") if mod.const_defined?("ClassMethods")
- class_eval(&mod._setup_block) if mod._setup_block
- end
-
- def depends_on(mod)
- return if self < mod
- @_dependencies ||= []
- @_dependencies << mod
- end
-end \ No newline at end of file
diff --git a/activesupport/lib/active_support/dependency_module.rb b/activesupport/lib/active_support/dependency_module.rb
new file mode 100644
index 0000000000..c690b49a2b
--- /dev/null
+++ b/activesupport/lib/active_support/dependency_module.rb
@@ -0,0 +1,24 @@
+module ActiveSupport
+ module DependencyModule
+ def append_features(base)
+ return if base < self
+ (@_dependencies ||= []).each { |dep| base.send(:include, dep) }
+ super
+ end
+
+ def included(base = nil, &block)
+ if base.nil? && block_given?
+ @_included_block = block
+ else
+ base.extend const_get("ClassMethods") if const_defined?("ClassMethods")
+ base.class_eval(&@_included_block) if instance_variable_defined?("@_included_block")
+ end
+ end
+
+ def depends_on(mod)
+ return if self < mod
+ @_dependencies ||= []
+ @_dependencies << mod
+ end
+ end
+end
diff --git a/activesupport/test/dependency_module_test.rb b/activesupport/test/dependency_module_test.rb
new file mode 100644
index 0000000000..07090d15a1
--- /dev/null
+++ b/activesupport/test/dependency_module_test.rb
@@ -0,0 +1,77 @@
+require 'abstract_unit'
+require 'active_support/dependency_module'
+
+class DependencyModuleTest < Test::Unit::TestCase
+ module Baz
+ extend ActiveSupport::DependencyModule
+
+ module ClassMethods
+ def baz
+ "baz"
+ end
+
+ def included_ran=(value)
+ @@included_ran = value
+ end
+
+ def included_ran
+ @@included_ran
+ end
+ end
+
+ included do
+ self.included_ran = true
+ end
+
+ def baz
+ "baz"
+ end
+ end
+
+ module Bar
+ extend ActiveSupport::DependencyModule
+
+ depends_on Baz
+
+ def bar
+ "bar"
+ end
+
+ def baz
+ "bar+" + super
+ end
+ end
+
+ def setup
+ @klass = Class.new
+ end
+
+ def test_module_is_included_normally
+ @klass.send(:include, Baz)
+ assert_equal "baz", @klass.new.baz
+ assert_equal DependencyModuleTest::Baz, @klass.included_modules[0]
+
+ @klass.send(:include, Baz)
+ assert_equal "baz", @klass.new.baz
+ assert_equal DependencyModuleTest::Baz, @klass.included_modules[0]
+ end
+
+ def test_class_methods_are_extended
+ @klass.send(:include, Baz)
+ assert_equal "baz", @klass.baz
+ assert_equal DependencyModuleTest::Baz::ClassMethods, (class << @klass; self.included_modules; end)[0]
+ end
+
+ def test_included_block_is_ran
+ @klass.send(:include, Baz)
+ assert_equal true, @klass.included_ran
+ end
+
+ def test_modules_dependencies_are_met
+ @klass.send(:include, Bar)
+ assert_equal "bar", @klass.new.bar
+ assert_equal "bar+baz", @klass.new.baz
+ assert_equal "baz", @klass.baz
+ assert_equal [DependencyModuleTest::Bar, DependencyModuleTest::Baz], @klass.included_modules[0..1]
+ end
+end
diff --git a/railties/lib/initializer.rb b/railties/lib/initializer.rb
index 71366a4480..9d27488e8a 100644
--- a/railties/lib/initializer.rb
+++ b/railties/lib/initializer.rb
@@ -462,7 +462,7 @@ Run `rake gems:install` to install the missing gems.
if RAILS_CACHE.respond_to?(:middleware)
# Insert middleware to setup and teardown local cache for each request
- configuration.middleware.insert_after(:"ActionController::Failsafe", RAILS_CACHE.middleware)
+ configuration.middleware.insert_after(:"ActionDispatch::Failsafe", RAILS_CACHE.middleware)
end
end
end
diff --git a/railties/lib/tasks/gems.rake b/railties/lib/tasks/gems.rake
index efadb1da3b..7cf7061f38 100644
--- a/railties/lib/tasks/gems.rake
+++ b/railties/lib/tasks/gems.rake
@@ -27,8 +27,7 @@ namespace :gems do
desc "Force the build of all gems"
task :force do
$gems_build_rake_task = true
- Rake::Task['gems:unpack'].invoke
- current_gems.each { |gem| gem.build(:force => true) }
+ frozen_gems.each { |gem| gem.build(:force => true) }
end
end
diff --git a/tools/profile_requires.rb b/tools/profile_requires.rb
new file mode 100644
index 0000000000..68d0de3d80
--- /dev/null
+++ b/tools/profile_requires.rb
@@ -0,0 +1,75 @@
+#!/usr/bin/env ruby
+# Example:
+# ruby -Iactivesupport/lib tools/profile_requires.rb active_support
+# ruby -Iactionpack/lib tools/profile_requires.rb action_controller
+abort 'Use REE so you can profile memory and object allocation' unless GC.respond_to?(:enable_stats)
+
+GC.enable_stats
+require 'rubygems'
+Gem.source_index
+require 'benchmark'
+
+module TrackHeapGrowth
+ class << self
+ attr_accessor :indent
+ attr_accessor :stats
+ end
+ self.indent = 0
+ self.stats = []
+
+ def track_growth(file)
+ TrackHeapGrowth.indent += 1
+ heap_before, objects_before = GC.allocated_size, ObjectSpace.allocated_objects
+ result = nil
+ elapsed = Benchmark.realtime { result = yield }
+ heap_after, objects_after = GC.allocated_size, ObjectSpace.allocated_objects
+ TrackHeapGrowth.indent -= 1
+ TrackHeapGrowth.stats << [file, TrackHeapGrowth.indent, elapsed, heap_after - heap_before, objects_after - objects_before] if result
+ result
+ end
+
+ def require(file, *args)
+ track_growth(file) { super }
+ end
+
+ def load(file, *args)
+ track_growth(file) { super }
+ end
+end
+
+Object.instance_eval { include TrackHeapGrowth }
+
+GC.start
+before = GC.allocated_size
+before_rss = `ps -o rss= -p #{Process.pid}`.to_i
+before_live_objects = ObjectSpace.live_objects
+
+path = ARGV.shift
+
+if mode = ARGV.shift
+ require 'ruby-prof'
+ RubyProf.measure_mode = RubyProf.const_get(mode.upcase)
+ RubyProf.start
+end
+
+ENV['NO_RELOAD'] ||= '1'
+ENV['RAILS_ENV'] ||= 'development'
+elapsed = Benchmark.realtime { require path }
+results = RubyProf.stop if mode
+
+GC.start
+after_live_objects = ObjectSpace.live_objects
+after_rss = `ps -o rss= -p #{Process.pid}`.to_i
+after = GC.allocated_size
+usage = (after - before) / 1024.0
+
+if mode
+ File.open("profile_startup.#{mode}.tree", 'w') do |out|
+ RubyProf::CallTreePrinter.new(results).print(out)
+ end
+end
+
+TrackHeapGrowth.stats.reverse_each do |file, indent, sec, bytes, objects|
+ puts "%10.2f KB %10d obj %8.1f ms %s%s" % [bytes / 1024.0, objects, sec * 1000, ' ' * indent, file]
+end
+puts "%10.2f KB %10d obj %8.1f ms %d KB RSS" % [usage, after_live_objects - before_live_objects, elapsed * 1000, after_rss - before_rss]