diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index 8a65945e61..ec49d40a12 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -1,6 +1,7 @@ require 'yaml' require 'set' require 'active_support/dependencies' +require 'active_support/time' require 'active_support/core_ext/class/attribute_accessors' require 'active_support/core_ext/class/delegating_attributes' require 'active_support/core_ext/class/inheritable_attributes' @@ -10,7 +11,6 @@ require 'active_support/core_ext/hash/indifferent_access' require 'active_support/core_ext/hash/slice' require 'active_support/core_ext/string/behavior' require 'active_support/core_ext/symbol' -require 'active_support/core/time' module ActiveRecord #:nodoc: # Generic Active Record exception class. diff --git a/activesupport/lib/active_support.rb b/activesupport/lib/active_support.rb index dab017770d..a1a140bc33 100644 --- a/activesupport/lib/active_support.rb +++ b/activesupport/lib/active_support.rb @@ -22,8 +22,15 @@ #++ module ActiveSupport - def self.load_all! - [Dependencies, Deprecation, Gzip, MessageVerifier, Multibyte, SecureRandom] + Core.load_all! + class << self + attr_accessor :load_all_hooks + def on_load_all(&hook) load_all_hooks << hook end + def load_all!; load_all_hooks.each { |hook| hook.call } end + end + self.load_all_hooks = [] + + on_load_all do + [Dependencies, Deprecation, Gzip, MessageVerifier, Multibyte, SecureRandom] end autoload :BacktraceCleaner, 'active_support/backtrace_cleaner' diff --git a/activesupport/lib/active_support/all.rb b/activesupport/lib/active_support/all.rb new file mode 100644 index 0000000000..f537818300 --- /dev/null +++ b/activesupport/lib/active_support/all.rb @@ -0,0 +1,3 @@ +require 'active_support' +require 'active_support/time' +require 'active_support/core_ext' diff --git a/activesupport/lib/active_support/core.rb b/activesupport/lib/active_support/core.rb deleted file mode 100644 index ad8db94941..0000000000 --- a/activesupport/lib/active_support/core.rb +++ /dev/null @@ -1,7 +0,0 @@ -module ActiveSupport - module Core - def self.load_all! - [TimeWithZone] - end - end -end diff --git a/activesupport/lib/active_support/core/all.rb b/activesupport/lib/active_support/core/all.rb deleted file mode 100644 index 55e8b4cfac..0000000000 --- a/activesupport/lib/active_support/core/all.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'active_support/core_ext' -require 'active_support/core' -Dir["#{File.dirname(__FILE__)}/*.rb"].sort.each do |path| - require "active_support/core/#{File.basename(path, '.rb')}" -end diff --git a/activesupport/lib/active_support/core/time.rb b/activesupport/lib/active_support/core/time.rb deleted file mode 100644 index 43e13b5e58..0000000000 --- a/activesupport/lib/active_support/core/time.rb +++ /dev/null @@ -1,4 +0,0 @@ -require 'active_support/core/time/autoload' -require 'active_support/core_ext/time' -require 'active_support/core_ext/date' -require 'active_support/core_ext/date_time' diff --git a/activesupport/lib/active_support/core_ext/hash/conversions.rb b/activesupport/lib/active_support/core_ext/hash/conversions.rb index fe1f79050c..2a34874d08 100644 --- a/activesupport/lib/active_support/core_ext/hash/conversions.rb +++ b/activesupport/lib/active_support/core_ext/hash/conversions.rb @@ -1,8 +1,7 @@ -require 'date' +require 'active_support/time' require 'active_support/core_ext/object/conversions' require 'active_support/core_ext/array/conversions' require 'active_support/core_ext/hash/reverse_merge' -require 'active_support/core/time' class Hash # This module exists to decorate files deserialized using Hash.from_xml with diff --git a/activesupport/lib/active_support/time.rb b/activesupport/lib/active_support/time.rb new file mode 100644 index 0000000000..d36a683601 --- /dev/null +++ b/activesupport/lib/active_support/time.rb @@ -0,0 +1,14 @@ +require 'active_support' +require 'active_support/core_ext/time' +require 'active_support/core_ext/date' +require 'active_support/core_ext/date_time' + +module ActiveSupport + autoload :Duration, 'active_support/duration' + autoload :TimeWithZone, 'active_support/time_with_zone' + autoload :TimeZone, 'active_support/values/time_zone' + + on_load_all do + [Duration, TimeWithZone, TimeZone] + end +end diff --git a/activesupport/lib/active_support/core/time/autoload.rb b/activesupport/lib/active_support/time/autoload.rb similarity index 100% rename from activesupport/lib/active_support/core/time/autoload.rb rename to activesupport/lib/active_support/time/autoload.rb diff --git a/activesupport/test/core_ext/duration_test.rb b/activesupport/test/core_ext/duration_test.rb index 30d4152729..6f16621ae5 100644 --- a/activesupport/test/core_ext/duration_test.rb +++ b/activesupport/test/core_ext/duration_test.rb @@ -1,5 +1,5 @@ require 'abstract_unit' -require 'active_support/core/time' +require 'active_support/time' class DurationTest < ActiveSupport::TestCase def test_inspect diff --git a/activesupport/test/core_ext/numeric_ext_test.rb b/activesupport/test/core_ext/numeric_ext_test.rb index 74b086fa9c..992ec60302 100644 --- a/activesupport/test/core_ext/numeric_ext_test.rb +++ b/activesupport/test/core_ext/numeric_ext_test.rb @@ -1,7 +1,7 @@ require 'abstract_unit' +require 'active_support/time' require 'active_support/core_ext/numeric' require 'active_support/core_ext/integer' -require 'active_support/core/time' class NumericExtTimeAndDateTimeTest < Test::Unit::TestCase def setup diff --git a/activesupport/test/core_ext/object_and_class_ext_test.rb b/activesupport/test/core_ext/object_and_class_ext_test.rb index 8869b053e6..f0121b862d 100644 --- a/activesupport/test/core_ext/object_and_class_ext_test.rb +++ b/activesupport/test/core_ext/object_and_class_ext_test.rb @@ -1,7 +1,7 @@ require 'abstract_unit' +require 'active_support/time' require 'active_support/core_ext/object' require 'active_support/core_ext/class/removal' -require 'active_support/core/time' class ClassA; end class ClassB < ClassA; end diff --git a/activesupport/test/core_ext/time_ext_test.rb b/activesupport/test/core_ext/time_ext_test.rb index e265423f06..1c2d0fbce4 100644 --- a/activesupport/test/core_ext/time_ext_test.rb +++ b/activesupport/test/core_ext/time_ext_test.rb @@ -1,5 +1,5 @@ require 'abstract_unit' -require 'active_support/core/time' +require 'active_support/time' class TimeExtCalculationsTest < Test::Unit::TestCase def test_seconds_since_midnight diff --git a/activesupport/test/i18n_test.rb b/activesupport/test/i18n_test.rb index 2a08abfb3e..9868f1e87d 100644 --- a/activesupport/test/i18n_test.rb +++ b/activesupport/test/i18n_test.rb @@ -1,5 +1,5 @@ require 'abstract_unit' -require 'active_support/core/time' +require 'active_support/time' require 'active_support/core_ext/array/conversions' class I18nTest < Test::Unit::TestCase diff --git a/activesupport/test/time_zone_test.rb b/activesupport/test/time_zone_test.rb index 87d6ccc30d..99c4310854 100644 --- a/activesupport/test/time_zone_test.rb +++ b/activesupport/test/time_zone_test.rb @@ -1,5 +1,5 @@ require 'abstract_unit' -require 'active_support/core/time' +require 'active_support/time' class TimeZoneTest < Test::Unit::TestCase def test_utc_to_local diff --git a/railties/lib/console_app.rb b/railties/lib/console_app.rb index 42bf50e01e..75e6f11ea3 100644 --- a/railties/lib/console_app.rb +++ b/railties/lib/console_app.rb @@ -1,5 +1,4 @@ -require 'active_support' -require 'active_support/core/all' +require 'active_support/all' require 'active_support/test_case' require 'action_controller' diff --git a/railties/lib/initializer.rb b/railties/lib/initializer.rb index 4c6de48a65..3c0d5940ea 100644 --- a/railties/lib/initializer.rb +++ b/railties/lib/initializer.rb @@ -263,9 +263,8 @@ module Rails # list. By default, all frameworks (Active Record, Active Support, # Action Pack, Action Mailer, and Active Resource) are loaded. def require_frameworks - require 'active_support' + require 'active_support/all' configuration.frameworks.each { |framework| require(framework.to_s) } - require 'active_support/core/all' rescue LoadError => e # Re-raise as RuntimeError because Mongrel would swallow LoadError. raise e.to_s diff --git a/railties/lib/rails_generator.rb b/railties/lib/rails_generator.rb index 201a9e0f91..85400932dd 100644 --- a/railties/lib/rails_generator.rb +++ b/railties/lib/rails_generator.rb @@ -21,16 +21,9 @@ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #++ -begin - require 'active_support' -rescue LoadError - activesupport_path = "#{File.dirname(__FILE__)}/../../activesupport/lib" - if File.directory?(activesupport_path) - $:.unshift activesupport_path - require 'active_support' - end -end -require 'active_support/core/all' +activesupport_path = "#{File.dirname(__FILE__)}/../../activesupport/lib" +$:.unshift(activesupport_path) if File.directory?(activesupport_path) +require 'active_support/all' $:.unshift(File.dirname(__FILE__)) require 'rails_generator/base' diff --git a/railties/lib/tasks/misc.rake b/railties/lib/tasks/misc.rake index a2c338aa5b..fb2fc31dc1 100644 --- a/railties/lib/tasks/misc.rake +++ b/railties/lib/tasks/misc.rake @@ -31,7 +31,7 @@ namespace :time do desc 'Displays names of time zones recognized by the Rails TimeZone class with the same offset as the system local time' task :local do require 'active_support' - require 'active_support/core/time' + require 'active_support/time' jan_offset = Time.now.beginning_of_year.utc_offset jul_offset = Time.now.beginning_of_year.change(:month => 7).utc_offset offset = jan_offset < jul_offset ? jan_offset : jul_offset @@ -41,7 +41,7 @@ namespace :time do # to find UTC -06:00 zones, OFFSET can be set to either -6, -6:00 or 21600 def build_time_zone_list(method, offset = ENV['OFFSET']) require 'active_support' - require 'active_support/core/time' + require 'active_support/time' if offset offset = if offset.to_s.match(/(\+|-)?(\d+):(\d+)/) sign = $1 == '-' ? -1 : 1