From 8e4363de72c0829c68d38f636b7fcefce6a5759a Mon Sep 17 00:00:00 2001 From: Yehuda Katz Date: Sun, 14 Feb 2010 11:35:05 -0800 Subject: Save off Module's const_missing, not Class' --- activesupport/lib/active_support/dependencies.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activesupport/lib/active_support') diff --git a/activesupport/lib/active_support/dependencies.rb b/activesupport/lib/active_support/dependencies.rb index 56de29b730..ee7566f335 100644 --- a/activesupport/lib/active_support/dependencies.rb +++ b/activesupport/lib/active_support/dependencies.rb @@ -116,7 +116,7 @@ module ActiveSupport #:nodoc: base.class_eval do # Emulate #exclude via an ivar return if @_const_missing - @_const_missing = method(:const_missing) + @_const_missing = instance_method(:const_missing) remove_method(:const_missing) end super -- cgit v1.2.3 From 411c15ed5220cb07cfb1989d32be956f94a7478f Mon Sep 17 00:00:00 2001 From: Yehuda Katz Date: Sun, 14 Feb 2010 11:55:01 -0800 Subject: require Strings, not Symbols --- activesupport/lib/active_support/dependencies.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'activesupport/lib/active_support') diff --git a/activesupport/lib/active_support/dependencies.rb b/activesupport/lib/active_support/dependencies.rb index ee7566f335..22b5e434c8 100644 --- a/activesupport/lib/active_support/dependencies.rb +++ b/activesupport/lib/active_support/dependencies.rb @@ -177,6 +177,7 @@ module ActiveSupport #:nodoc: end def require_dependency(file_name, message = "No such file to load -- %s") + raise ArgumentError, "the file name must be a String -- you passed #{file_name.inspect}" Dependencies.depend_on(file_name, false, message) end -- cgit v1.2.3 From 38eb2f145432429d866ab62f796dd7055d1c524a Mon Sep 17 00:00:00 2001 From: Yehuda Katz Date: Sun, 14 Feb 2010 12:13:37 -0800 Subject: Right. --- activesupport/lib/active_support/dependencies.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'activesupport/lib/active_support') diff --git a/activesupport/lib/active_support/dependencies.rb b/activesupport/lib/active_support/dependencies.rb index 22b5e434c8..87d56eb17e 100644 --- a/activesupport/lib/active_support/dependencies.rb +++ b/activesupport/lib/active_support/dependencies.rb @@ -177,7 +177,10 @@ module ActiveSupport #:nodoc: end def require_dependency(file_name, message = "No such file to load -- %s") - raise ArgumentError, "the file name must be a String -- you passed #{file_name.inspect}" + unless file_name.is_a?(String) + raise ArgumentError, "the file name must be a String -- you passed #{file_name.inspect}" + end + Dependencies.depend_on(file_name, false, message) end -- cgit v1.2.3 From f0523f72b46db14e2f50c8347a8708734c650f84 Mon Sep 17 00:00:00 2001 From: Prem Sichanugrist Date: Mon, 15 Feb 2010 21:44:30 +0700 Subject: Rename Rails::Subscriber to Rails::LogSubscriber --- activesupport/lib/active_support/notifications.rb | 4 ++-- activesupport/lib/active_support/notifications/fanout.rb | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) (limited to 'activesupport/lib/active_support') diff --git a/activesupport/lib/active_support/notifications.rb b/activesupport/lib/active_support/notifications.rb index 3e96decb8c..06d57765bc 100644 --- a/activesupport/lib/active_support/notifications.rb +++ b/activesupport/lib/active_support/notifications.rb @@ -9,7 +9,7 @@ module ActiveSupport # end # # You can consume those events and the information they provide by registering - # a subscriber. For instance, let's store all instrumented events in an array: + # a log subscriber. For instance, let's store all instrumented events in an array: # # @events = [] # @@ -35,7 +35,7 @@ module ActiveSupport # end # # Notifications ships with a queue implementation that consumes and publish events - # to subscribers in a thread. You can use any queue implementation you want. + # to log subscribers in a thread. You can use any queue implementation you want. # module Notifications autoload :Instrumenter, 'active_support/notifications/instrumenter' diff --git a/activesupport/lib/active_support/notifications/fanout.rb b/activesupport/lib/active_support/notifications/fanout.rb index 0ec23da073..05de4946a5 100644 --- a/activesupport/lib/active_support/notifications/fanout.rb +++ b/activesupport/lib/active_support/notifications/fanout.rb @@ -1,10 +1,10 @@ module ActiveSupport module Notifications # This is a default queue implementation that ships with Notifications. It - # just pushes events to all registered subscribers. + # just pushes events to all registered log subscribers. class Fanout def initialize - @subscribers = [] + @log_subscribers = [] end def bind(pattern) @@ -12,11 +12,11 @@ module ActiveSupport end def subscribe(pattern = nil, &block) - @subscribers << Subscriber.new(pattern, &block) + @log_subscribers << LogSubscriber.new(pattern, &block) end def publish(*args) - @subscribers.each { |s| s.publish(*args) } + @log_subscribers.each { |s| s.publish(*args) } end # This is a sync queue, so there is not waiting. @@ -41,7 +41,7 @@ module ActiveSupport end end - class Subscriber #:nodoc: + class LogSubscriber #:nodoc: def initialize(pattern, &block) @pattern = pattern @block = block -- cgit v1.2.3 From cc852e2580575b715134cce65d6b3dc8826fe918 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Thu, 18 Feb 2010 10:47:45 -0800 Subject: Use FileUtils.mv instead of rename to copy in case of cross-device links --- activesupport/lib/active_support/core_ext/file/atomic.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'activesupport/lib/active_support') diff --git a/activesupport/lib/active_support/core_ext/file/atomic.rb b/activesupport/lib/active_support/core_ext/file/atomic.rb index 49d28e8a34..26b73ed442 100644 --- a/activesupport/lib/active_support/core_ext/file/atomic.rb +++ b/activesupport/lib/active_support/core_ext/file/atomic.rb @@ -14,6 +14,7 @@ class File # end def self.atomic_write(file_name, temp_dir = Dir.tmpdir) require 'tempfile' unless defined?(Tempfile) + require 'fileutils' unless defined?(FileUtils) temp_file = Tempfile.new(basename(file_name), temp_dir) yield temp_file @@ -31,7 +32,7 @@ class File end # Overwrite original file with temp file - rename(temp_file.path, file_name) + FileUtils.mv(temp_file.path, file_name) # Set correct permissions on new file chown(old_stat.uid, old_stat.gid, file_name) -- cgit v1.2.3 From 98c299fba5bdaf3f1c156c2e16a5a95a5d9cf251 Mon Sep 17 00:00:00 2001 From: Yehuda Katz Date: Thu, 18 Feb 2010 14:04:08 -0800 Subject: Don't constantize possible module names when looking for new constants unless they exist --- activesupport/lib/active_support/dependencies.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'activesupport/lib/active_support') diff --git a/activesupport/lib/active_support/dependencies.rb b/activesupport/lib/active_support/dependencies.rb index 87d56eb17e..107f664960 100644 --- a/activesupport/lib/active_support/dependencies.rb +++ b/activesupport/lib/active_support/dependencies.rb @@ -78,6 +78,7 @@ module ActiveSupport #:nodoc: def new_constants_for(frames) frames.map do |mod_name, prior_constants| mod = Inflector.constantize(mod_name) + mod = Inflector.constantize(mod_name) if Dependencies.qualified_const_defined?(mod_name) next unless mod.is_a?(Module) new_constants = mod.local_constant_names - prior_constants -- cgit v1.2.3 From ae8c384e2c07da4870dd3919321a6d49aeff3588 Mon Sep 17 00:00:00 2001 From: Carl Lerche Date: Thu, 18 Feb 2010 16:29:32 -0800 Subject: Avoid calling triggering const_missing if const_missing is private when doing constantize --- activesupport/lib/active_support/inflector/methods.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activesupport/lib/active_support') diff --git a/activesupport/lib/active_support/inflector/methods.rb b/activesupport/lib/active_support/inflector/methods.rb index 41277893e3..c7df62e915 100644 --- a/activesupport/lib/active_support/inflector/methods.rb +++ b/activesupport/lib/active_support/inflector/methods.rb @@ -109,7 +109,7 @@ module ActiveSupport constant = Object names.each do |name| - constant = constant.const_get(name, false) || constant.const_missing(name) + constant = constant.const_defined?(name, false) ? constant.const_get(name) : constant.const_missing(name) end constant end -- cgit v1.2.3 From e6ce8564623c20b080a98cc5e6548ac14635c991 Mon Sep 17 00:00:00 2001 From: Yehuda Katz Date: Thu, 18 Feb 2010 16:48:28 -0800 Subject: Git fail --- activesupport/lib/active_support/dependencies.rb | 1 - 1 file changed, 1 deletion(-) (limited to 'activesupport/lib/active_support') diff --git a/activesupport/lib/active_support/dependencies.rb b/activesupport/lib/active_support/dependencies.rb index 107f664960..da1050298b 100644 --- a/activesupport/lib/active_support/dependencies.rb +++ b/activesupport/lib/active_support/dependencies.rb @@ -77,7 +77,6 @@ module ActiveSupport #:nodoc: def new_constants_for(frames) frames.map do |mod_name, prior_constants| - mod = Inflector.constantize(mod_name) mod = Inflector.constantize(mod_name) if Dependencies.qualified_const_defined?(mod_name) next unless mod.is_a?(Module) -- cgit v1.2.3 From 2f98032fc92ce16125f8628b4d3c283f10494f4d Mon Sep 17 00:00:00 2001 From: Yehuda Katz Date: Fri, 19 Feb 2010 10:10:45 -0800 Subject: Fix a problem where nil was appearing in the list --- activesupport/lib/active_support/dependencies.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'activesupport/lib/active_support') diff --git a/activesupport/lib/active_support/dependencies.rb b/activesupport/lib/active_support/dependencies.rb index da1050298b..a3a7df7464 100644 --- a/activesupport/lib/active_support/dependencies.rb +++ b/activesupport/lib/active_support/dependencies.rb @@ -76,17 +76,19 @@ module ActiveSupport #:nodoc: locked :concat, :each, :delete_if, :<< def new_constants_for(frames) - frames.map do |mod_name, prior_constants| + constants = [] + frames.each do |mod_name, prior_constants| mod = Inflector.constantize(mod_name) if Dependencies.qualified_const_defined?(mod_name) next unless mod.is_a?(Module) new_constants = mod.local_constant_names - prior_constants get(mod_name).concat(new_constants) - new_constants.map do |suffix| - ([mod_name, suffix] - ["Object"]).join("::") + new_constants.each do |suffix| + constants << ([mod_name, suffix] - ["Object"]).join("::") end - end.flatten + end + constants end # Add a set of modules to the watch stack, remembering the initial constants -- cgit v1.2.3 From 7ad2c5c06fe841d71b7fa0db8166f378b04693f8 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Fri, 19 Feb 2010 17:28:20 -0200 Subject: warning: instance variable @_const_missing not initialized fixed --- activesupport/lib/active_support/dependencies.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activesupport/lib/active_support') diff --git a/activesupport/lib/active_support/dependencies.rb b/activesupport/lib/active_support/dependencies.rb index a3a7df7464..96478ee947 100644 --- a/activesupport/lib/active_support/dependencies.rb +++ b/activesupport/lib/active_support/dependencies.rb @@ -117,7 +117,7 @@ module ActiveSupport #:nodoc: def self.append_features(base) base.class_eval do # Emulate #exclude via an ivar - return if @_const_missing + return if defined?(@_const_missing) && @_const_missing @_const_missing = instance_method(:const_missing) remove_method(:const_missing) end -- cgit v1.2.3 From e4b910f6a37fa0eb02b0545e7320cfe4d7ff2c04 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Fri, 19 Feb 2010 18:24:05 -0200 Subject: require publicize_conversion_method to ensure to_date and to_datetime became public before redefining them (avoid warnings) --- activesupport/lib/active_support/core_ext/string/conversions.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'activesupport/lib/active_support') diff --git a/activesupport/lib/active_support/core_ext/string/conversions.rb b/activesupport/lib/active_support/core_ext/string/conversions.rb index 331416b3a9..52946f9037 100644 --- a/activesupport/lib/active_support/core_ext/string/conversions.rb +++ b/activesupport/lib/active_support/core_ext/string/conversions.rb @@ -1,4 +1,5 @@ require 'date' +require 'active_support/core_ext/time/publicize_conversion_methods' require 'active_support/core_ext/time/calculations' class String -- cgit v1.2.3 From fed72b5842e5e8604917602a15c126d48cf12fde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sat, 20 Feb 2010 15:46:55 +0100 Subject: Rename engines_load_path to railties_load_path. --- activesupport/lib/active_support/railtie.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'activesupport/lib/active_support') diff --git a/activesupport/lib/active_support/railtie.rb b/activesupport/lib/active_support/railtie.rb index c8d8b85000..58d11585ba 100644 --- a/activesupport/lib/active_support/railtie.rb +++ b/activesupport/lib/active_support/railtie.rb @@ -33,7 +33,7 @@ module I18n railtie_name :i18n # Initialize I18n load paths to an array - config.i18n.engines_load_path = [] + config.i18n.railties_load_path = [] config.i18n.load_path = [] initializer "i18n.initialize" do @@ -49,7 +49,7 @@ module I18n config.after_initialize do |app| app.config.i18n.each do |setting, value| case setting - when :engines_load_path + when :railties_load_path app.config.i18n.load_path.unshift(*value) when :load_path I18n.load_path += value -- cgit v1.2.3 From 3345af61fb128d0a70793b235e3cb878781d6f40 Mon Sep 17 00:00:00 2001 From: Carlhuda Date: Tue, 23 Feb 2010 15:37:17 -0800 Subject: Fix streaming by having it create a File object, which can be handled by Rack servers as appropriate --- activesupport/lib/active_support/ruby/shim.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'activesupport/lib/active_support') diff --git a/activesupport/lib/active_support/ruby/shim.rb b/activesupport/lib/active_support/ruby/shim.rb index 1e49ccdade..f0db5b3021 100644 --- a/activesupport/lib/active_support/ruby/shim.rb +++ b/activesupport/lib/active_support/ruby/shim.rb @@ -17,3 +17,4 @@ require 'active_support/core_ext/string/conversions' require 'active_support/core_ext/string/interpolation' require 'active_support/core_ext/rexml' require 'active_support/core_ext/time/conversions' +require 'active_support/core_ext/file/path' -- cgit v1.2.3 From 47498a7f59d0196e9b8aa8e3569cbb4937477cef Mon Sep 17 00:00:00 2001 From: Carlhuda Date: Tue, 23 Feb 2010 17:42:14 -0800 Subject: Woops, forgot to actually add active_support/core_ext/file/path.rb --- activesupport/lib/active_support/core_ext/file/path.rb | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 activesupport/lib/active_support/core_ext/file/path.rb (limited to 'activesupport/lib/active_support') diff --git a/activesupport/lib/active_support/core_ext/file/path.rb b/activesupport/lib/active_support/core_ext/file/path.rb new file mode 100644 index 0000000000..b5feab80ae --- /dev/null +++ b/activesupport/lib/active_support/core_ext/file/path.rb @@ -0,0 +1,5 @@ +class File + unless File.allocate.respond_to?(:to_path) + alias to_path path + end +end \ No newline at end of file -- cgit v1.2.3 From 6b12d74026808a3014f1dff34481006a96e0f18f Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Thu, 25 Feb 2010 09:28:18 -0800 Subject: Commented metaprogramming turned out to be noisier not clearer --- activesupport/lib/active_support/core_ext/proc.rb | 6 +++--- .../lib/active_support/deprecation/method_wrappers.rb | 18 +++++++++--------- 2 files changed, 12 insertions(+), 12 deletions(-) (limited to 'activesupport/lib/active_support') diff --git a/activesupport/lib/active_support/core_ext/proc.rb b/activesupport/lib/active_support/core_ext/proc.rb index d50076a01e..71b413a88a 100644 --- a/activesupport/lib/active_support/core_ext/proc.rb +++ b/activesupport/lib/active_support/core_ext/proc.rb @@ -5,9 +5,9 @@ class Proc #:nodoc: block, time = self, Time.now object.class_eval do method_name = "__bind_#{time.to_i}_#{time.usec}" - define_method(method_name, &block) # define_method("__bind_1230458026_720454", &block) - method = instance_method(method_name) # method = instance_method("__bind_1230458026_720454") - remove_method(method_name) # remove_method("__bind_1230458026_720454") + define_method(method_name, &block) + method = instance_method(method_name) + remove_method(method_name) method end.bind(object) end diff --git a/activesupport/lib/active_support/deprecation/method_wrappers.rb b/activesupport/lib/active_support/deprecation/method_wrappers.rb index cec8024b17..d0d8b577b3 100644 --- a/activesupport/lib/active_support/deprecation/method_wrappers.rb +++ b/activesupport/lib/active_support/deprecation/method_wrappers.rb @@ -12,15 +12,15 @@ module ActiveSupport method_names.each do |method_name| target_module.alias_method_chain(method_name, :deprecation) do |target, punctuation| target_module.module_eval(<<-end_eval, __FILE__, __LINE__ + 1) - def #{target}_with_deprecation#{punctuation}(*args, &block) # def generate_secret_with_deprecation(*args, &block) - ::ActiveSupport::Deprecation.warn( # ::ActiveSupport::Deprecation.warn( - ::ActiveSupport::Deprecation.deprecated_method_warning( # ::ActiveSupport::Deprecation.deprecated_method_warning( - :#{method_name}, # :generate_secret, - #{options[method_name].inspect}), # "You should use ActiveSupport::SecureRandom.hex(64)"), - caller # caller - ) # ) - send(:#{target}_without_deprecation#{punctuation}, *args, &block) # send(:generate_secret_without_deprecation, *args, &block) - end # end + def #{target}_with_deprecation#{punctuation}(*args, &block) + ::ActiveSupport::Deprecation.warn( + ::ActiveSupport::Deprecation.deprecated_method_warning( + :#{method_name}, + #{options[method_name].inspect}), + caller + ) + send(:#{target}_without_deprecation#{punctuation}, *args, &block) + end end_eval end end -- cgit v1.2.3 From f7b0a857e97304a5daeb47313759b9bf0d7e2fc9 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Thu, 25 Feb 2010 09:32:29 -0800 Subject: Use Object#singleton_class instead of #metaclass. Prefer Ruby's choice. --- activesupport/lib/active_support/callbacks.rb | 4 ++-- activesupport/lib/active_support/core_ext/class/attribute.rb | 11 ++++++----- .../active_support/core_ext/class/delegating_attributes.rb | 12 ++++++------ activesupport/lib/active_support/core_ext/object.rb | 1 + .../lib/active_support/core_ext/object/metaclass.rb | 11 ++++++----- activesupport/lib/active_support/memoizable.rb | 2 +- 6 files changed, 22 insertions(+), 19 deletions(-) (limited to 'activesupport/lib/active_support') diff --git a/activesupport/lib/active_support/callbacks.rb b/activesupport/lib/active_support/callbacks.rb index 6727eda811..b230bb8a40 100644 --- a/activesupport/lib/active_support/callbacks.rb +++ b/activesupport/lib/active_support/callbacks.rb @@ -1,7 +1,7 @@ require 'active_support/core_ext/array/wrap' require 'active_support/core_ext/class/inheritable_attributes' require 'active_support/core_ext/kernel/reporting' -require 'active_support/core_ext/object/metaclass' +require 'active_support/core_ext/object/singleton_class' module ActiveSupport # Callbacks are hooks into the lifecycle of an object that allow you to trigger logic @@ -312,7 +312,7 @@ module ActiveSupport def _normalize_legacy_filter(kind, filter) if !filter.respond_to?(kind) && filter.respond_to?(:filter) - filter.metaclass.class_eval( + filter.singleton_class.class_eval( "def #{kind}(context, &block) filter(context, &block) end", __FILE__, __LINE__ - 1) elsif filter.respond_to?(:before) && filter.respond_to?(:after) && kind == :around diff --git a/activesupport/lib/active_support/core_ext/class/attribute.rb b/activesupport/lib/active_support/core_ext/class/attribute.rb index d74219cb93..1bd39a9349 100644 --- a/activesupport/lib/active_support/core_ext/class/attribute.rb +++ b/activesupport/lib/active_support/core_ext/class/attribute.rb @@ -1,4 +1,4 @@ -require 'active_support/core_ext/object/metaclass' +require 'active_support/core_ext/object/singleton_class' require 'active_support/core_ext/module/delegation' class Class @@ -25,11 +25,12 @@ class Class # # Subclass.setting? # => false def class_attribute(*attrs) + s = singleton_class attrs.each do |attr| - metaclass.send(:define_method, attr) { } - metaclass.send(:define_method, "#{attr}?") { !!send(attr) } - metaclass.send(:define_method, "#{attr}=") do |value| - metaclass.send(:define_method, attr) { value } + s.send(:define_method, attr) { } + s.send(:define_method, "#{attr}?") { !!send(attr) } + s.send(:define_method, "#{attr}=") do |value| + singleton_class.send(:define_method, attr) { value } end end end diff --git a/activesupport/lib/active_support/core_ext/class/delegating_attributes.rb b/activesupport/lib/active_support/core_ext/class/delegating_attributes.rb index 19382abb76..b5785bdcd3 100644 --- a/activesupport/lib/active_support/core_ext/class/delegating_attributes.rb +++ b/activesupport/lib/active_support/core_ext/class/delegating_attributes.rb @@ -1,6 +1,6 @@ require 'active_support/core_ext/object/blank' require 'active_support/core_ext/array/extract_options' -require 'active_support/core_ext/object/metaclass' +require 'active_support/core_ext/object/singleton_class' class Class def superclass_delegating_accessor(name, options = {}) @@ -11,9 +11,9 @@ class Class # Generate the public methods name, name=, and name? # These methods dispatch to the private _name, and _name= methods, making them # overridable - metaclass.send(:define_method, name) { send("_#{name}") } - metaclass.send(:define_method, "#{name}?") { !!send("_#{name}") } - metaclass.send(:define_method, "#{name}=") { |value| send("_#{name}=", value) } + singleton_class.send(:define_method, name) { send("_#{name}") } + singleton_class.send(:define_method, "#{name}?") { !!send("_#{name}") } + singleton_class.send(:define_method, "#{name}=") { |value| send("_#{name}=", value) } # If an instance_reader is needed, generate methods for name and name= on the # class itself, so instances will be able to see them @@ -27,12 +27,12 @@ private # inheritance behavior, without having to store the object in an instance # variable and look up the superclass chain manually. def _stash_object_in_method(object, method, instance_reader = true) - metaclass.send(:define_method, method) { object } + singleton_class.send(:define_method, method) { object } define_method(method) { object } if instance_reader end def _superclass_delegating_accessor(name, options = {}) - metaclass.send(:define_method, "#{name}=") do |value| + singleton_class.send(:define_method, "#{name}=") do |value| _stash_object_in_method(value, name, options[:instance_reader] != false) end self.send("#{name}=", nil) diff --git a/activesupport/lib/active_support/core_ext/object.rb b/activesupport/lib/active_support/core_ext/object.rb index db2dac1472..9dc6ca66a4 100644 --- a/activesupport/lib/active_support/core_ext/object.rb +++ b/activesupport/lib/active_support/core_ext/object.rb @@ -6,6 +6,7 @@ require 'active_support/core_ext/object/try' require 'active_support/core_ext/object/conversions' require 'active_support/core_ext/object/instance_variables' require 'active_support/core_ext/object/metaclass' +require 'active_support/core_ext/object/singleton_class' require 'active_support/core_ext/object/misc' require 'active_support/core_ext/object/extending' diff --git a/activesupport/lib/active_support/core_ext/object/metaclass.rb b/activesupport/lib/active_support/core_ext/object/metaclass.rb index 93fb0ad594..4b36a243c9 100644 --- a/activesupport/lib/active_support/core_ext/object/metaclass.rb +++ b/activesupport/lib/active_support/core_ext/object/metaclass.rb @@ -1,13 +1,14 @@ +require 'active_support/deprecation' + class Object - # Get object's meta (ghost, eigenclass, singleton) class + # Get object's meta (ghost, eigenclass, singleton) class. + # + # Deprecated in favor of Object#singleton_class. def metaclass class << self self end end - # If class_eval is called on an object, add those methods to its metaclass - def class_eval(*args, &block) - metaclass.class_eval(*args, &block) - end + deprecate :metaclass => :singleton_class end diff --git a/activesupport/lib/active_support/memoizable.rb b/activesupport/lib/active_support/memoizable.rb index f810f53029..ca1cfedae3 100644 --- a/activesupport/lib/active_support/memoizable.rb +++ b/activesupport/lib/active_support/memoizable.rb @@ -1,4 +1,4 @@ -require 'active_support/core_ext/object/metaclass' +require 'active_support/core_ext/object/singleton_class' require 'active_support/core_ext/module/aliasing' module ActiveSupport -- cgit v1.2.3 From 0b87d114bde73cddb9401d061acc1f2f4b3e1dfc Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Thu, 25 Feb 2010 10:57:29 -0800 Subject: Missed singleton_class --- .../lib/active_support/core_ext/object/singleton_class.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 activesupport/lib/active_support/core_ext/object/singleton_class.rb (limited to 'activesupport/lib/active_support') diff --git a/activesupport/lib/active_support/core_ext/object/singleton_class.rb b/activesupport/lib/active_support/core_ext/object/singleton_class.rb new file mode 100644 index 0000000000..8dee54e71b --- /dev/null +++ b/activesupport/lib/active_support/core_ext/object/singleton_class.rb @@ -0,0 +1,13 @@ +class Object + # Returns the object's singleton class. + def singleton_class + class << self + self + end + end unless respond_to?(:singleton_class) + + # class_eval on an object acts like singleton_class_eval. + def class_eval(*args, &block) + singleton_class.class_eval(*args, &block) + end +end -- cgit v1.2.3 From 763f32ab47b96289a4d7b7107411a83164bf69de Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Thu, 25 Feb 2010 11:12:27 -0800 Subject: metaclass deprecated in 2.3.6 --- activesupport/lib/active_support/core_ext/object.rb | 1 - .../lib/active_support/core_ext/object/metaclass.rb | 14 -------------- 2 files changed, 15 deletions(-) delete mode 100644 activesupport/lib/active_support/core_ext/object/metaclass.rb (limited to 'activesupport/lib/active_support') diff --git a/activesupport/lib/active_support/core_ext/object.rb b/activesupport/lib/active_support/core_ext/object.rb index 9dc6ca66a4..4f86d9d605 100644 --- a/activesupport/lib/active_support/core_ext/object.rb +++ b/activesupport/lib/active_support/core_ext/object.rb @@ -5,7 +5,6 @@ require 'active_support/core_ext/object/try' require 'active_support/core_ext/object/conversions' require 'active_support/core_ext/object/instance_variables' -require 'active_support/core_ext/object/metaclass' require 'active_support/core_ext/object/singleton_class' require 'active_support/core_ext/object/misc' require 'active_support/core_ext/object/extending' diff --git a/activesupport/lib/active_support/core_ext/object/metaclass.rb b/activesupport/lib/active_support/core_ext/object/metaclass.rb deleted file mode 100644 index 4b36a243c9..0000000000 --- a/activesupport/lib/active_support/core_ext/object/metaclass.rb +++ /dev/null @@ -1,14 +0,0 @@ -require 'active_support/deprecation' - -class Object - # Get object's meta (ghost, eigenclass, singleton) class. - # - # Deprecated in favor of Object#singleton_class. - def metaclass - class << self - self - end - end - - deprecate :metaclass => :singleton_class -end -- cgit v1.2.3 From d8acaf2b66be431ccd594cb90afc4ef2dc470b34 Mon Sep 17 00:00:00 2001 From: Yehuda Katz Date: Sat, 27 Feb 2010 11:51:19 -0800 Subject: Remove the noisy lines involving AS::Dependencies from the NameError stack trace if a constant cannot be found. --- activesupport/lib/active_support/dependencies.rb | 3 +++ 1 file changed, 3 insertions(+) (limited to 'activesupport/lib/active_support') diff --git a/activesupport/lib/active_support/dependencies.rb b/activesupport/lib/active_support/dependencies.rb index 96478ee947..2d7aa7e1e6 100644 --- a/activesupport/lib/active_support/dependencies.rb +++ b/activesupport/lib/active_support/dependencies.rb @@ -441,7 +441,10 @@ module ActiveSupport #:nodoc: qualified_name = qualified_name_for from_mod, const_name path_suffix = qualified_name.underscore + + trace = caller.reject {|l| l =~ %r{#{__FILE__}}} name_error = NameError.new("uninitialized constant #{qualified_name}") + name_error.set_backtrace(trace) file_path = search_for_file(path_suffix) -- cgit v1.2.3 From 1c9de08734f5305f5cff560a192f7f58d3f3fc11 Mon Sep 17 00:00:00 2001 From: Yehuda Katz Date: Sat, 27 Feb 2010 12:18:28 -0800 Subject: Escape the file name (who knows when a "(" might appear in a filename!) --- activesupport/lib/active_support/dependencies.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activesupport/lib/active_support') diff --git a/activesupport/lib/active_support/dependencies.rb b/activesupport/lib/active_support/dependencies.rb index 2d7aa7e1e6..9c4412c28c 100644 --- a/activesupport/lib/active_support/dependencies.rb +++ b/activesupport/lib/active_support/dependencies.rb @@ -442,7 +442,7 @@ module ActiveSupport #:nodoc: qualified_name = qualified_name_for from_mod, const_name path_suffix = qualified_name.underscore - trace = caller.reject {|l| l =~ %r{#{__FILE__}}} + trace = caller.reject {|l| l =~ %r{#{Regexp.escape(__FILE__)}}} name_error = NameError.new("uninitialized constant #{qualified_name}") name_error.set_backtrace(trace) -- cgit v1.2.3 From 2060977b767061a42eb8db2d5c3a30d205a94123 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lourens=20Naud=C3=A9?= Date: Mon, 8 Feb 2010 00:05:33 +0000 Subject: Hash#symbolize_keys(!) optimizations [#3891 state:committed] Signed-off-by: Jeremy Kemper --- activesupport/lib/active_support/core_ext/hash/keys.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activesupport/lib/active_support') diff --git a/activesupport/lib/active_support/core_ext/hash/keys.rb b/activesupport/lib/active_support/core_ext/hash/keys.rb index 045a6944fa..e4d429fc2b 100644 --- a/activesupport/lib/active_support/core_ext/hash/keys.rb +++ b/activesupport/lib/active_support/core_ext/hash/keys.rb @@ -22,7 +22,7 @@ class Hash # to +to_sym+. def symbolize_keys! keys.each do |key| - self[(key.to_sym rescue key) || key] = delete(key) + self[(key.to_sym rescue key)] = delete(key) if key.respond_to?(:to_sym) && !key.is_a?(Fixnum) end self end -- cgit v1.2.3 From 048b436f33059f1da7659edf9ca05fb46042b253 Mon Sep 17 00:00:00 2001 From: Carlhuda Date: Mon, 1 Mar 2010 15:54:45 -0800 Subject: AS::Subscriber is not a LogSubscriber --- activesupport/lib/active_support/notifications/fanout.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'activesupport/lib/active_support') diff --git a/activesupport/lib/active_support/notifications/fanout.rb b/activesupport/lib/active_support/notifications/fanout.rb index 05de4946a5..090eb1eac6 100644 --- a/activesupport/lib/active_support/notifications/fanout.rb +++ b/activesupport/lib/active_support/notifications/fanout.rb @@ -12,7 +12,7 @@ module ActiveSupport end def subscribe(pattern = nil, &block) - @log_subscribers << LogSubscriber.new(pattern, &block) + @log_subscribers << Subscriber.new(pattern, &block) end def publish(*args) @@ -41,7 +41,7 @@ module ActiveSupport end end - class LogSubscriber #:nodoc: + class Subscriber #:nodoc: def initialize(pattern, &block) @pattern = pattern @block = block -- cgit v1.2.3 From c88360ef3651702ca8f7f600e15774f51c84698b Mon Sep 17 00:00:00 2001 From: Carlhuda Date: Mon, 1 Mar 2010 16:01:08 -0800 Subject: You can unsubscribe a subscriber --- activesupport/lib/active_support/notifications.rb | 4 ++++ activesupport/lib/active_support/notifications/fanout.rb | 11 ++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) (limited to 'activesupport/lib/active_support') diff --git a/activesupport/lib/active_support/notifications.rb b/activesupport/lib/active_support/notifications.rb index 06d57765bc..fca2efd969 100644 --- a/activesupport/lib/active_support/notifications.rb +++ b/activesupport/lib/active_support/notifications.rb @@ -69,6 +69,10 @@ module ActiveSupport @queue.bind(pattern).subscribe(&block) end + def unsubscribe(subscriber) + @queue.unsubscribe(subscriber) + end + def wait @queue.wait end diff --git a/activesupport/lib/active_support/notifications/fanout.rb b/activesupport/lib/active_support/notifications/fanout.rb index 090eb1eac6..e08011e23f 100644 --- a/activesupport/lib/active_support/notifications/fanout.rb +++ b/activesupport/lib/active_support/notifications/fanout.rb @@ -4,7 +4,7 @@ module ActiveSupport # just pushes events to all registered log subscribers. class Fanout def initialize - @log_subscribers = [] + @subscribers = [] end def bind(pattern) @@ -12,11 +12,16 @@ module ActiveSupport end def subscribe(pattern = nil, &block) - @log_subscribers << Subscriber.new(pattern, &block) + @subscribers << Subscriber.new(pattern, &block) + @subscribers.last + end + + def unsubscribe(subscriber) + @subscribers.delete(subscriber) end def publish(*args) - @log_subscribers.each { |s| s.publish(*args) } + @subscribers.each { |s| s.publish(*args) } end # This is a sync queue, so there is not waiting. -- cgit v1.2.3 From fc0882ba5a0f18281736859718252042b15614ad Mon Sep 17 00:00:00 2001 From: Carlhuda Date: Mon, 1 Mar 2010 17:33:59 -0800 Subject: Optimize AS::Notifications to remember which subscribers don't match and not run them. This will allow notifications that are only useful in dev or testing to run efficiently in production. --- activesupport/lib/active_support/notifications.rb | 2 +- activesupport/lib/active_support/notifications/fanout.rb | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) (limited to 'activesupport/lib/active_support') diff --git a/activesupport/lib/active_support/notifications.rb b/activesupport/lib/active_support/notifications.rb index fca2efd969..3f1fe64e9b 100644 --- a/activesupport/lib/active_support/notifications.rb +++ b/activesupport/lib/active_support/notifications.rb @@ -44,7 +44,7 @@ module ActiveSupport class << self attr_writer :notifier - delegate :publish, :subscribe, :to => :notifier + delegate :publish, :subscribe, :unsubscribe, :to => :notifier delegate :instrument, :to => :instrumenter def notifier diff --git a/activesupport/lib/active_support/notifications/fanout.rb b/activesupport/lib/active_support/notifications/fanout.rb index e08011e23f..cd60054862 100644 --- a/activesupport/lib/active_support/notifications/fanout.rb +++ b/activesupport/lib/active_support/notifications/fanout.rb @@ -5,6 +5,7 @@ module ActiveSupport class Fanout def initialize @subscribers = [] + @listeners_for = {} end def bind(pattern) @@ -12,16 +13,22 @@ module ActiveSupport end def subscribe(pattern = nil, &block) + @listeners_for.clear @subscribers << Subscriber.new(pattern, &block) @subscribers.last end def unsubscribe(subscriber) @subscribers.delete(subscriber) + @listeners_for.clear end - def publish(*args) - @subscribers.each { |s| s.publish(*args) } + def publish(name, *args) + if listeners = @listeners_for[name] + listeners.each { |s| s.publish(name, *args) } + else + @listeners_for[name] = @subscribers.select { |s| s.publish(name, *args) } + end end # This is a sync queue, so there is not waiting. @@ -53,7 +60,9 @@ module ActiveSupport end def publish(*args) - push(*args) if matches?(args.first) + return unless matches?(args.first) + push(*args) + true end def drained? -- cgit v1.2.3 From a4111bbca0884e4a748ab32ba7d7b550ec8d9186 Mon Sep 17 00:00:00 2001 From: Bryan Helmkamp Date: Mon, 1 Mar 2010 23:03:07 -0500 Subject: Update versions of all components to normalize them to new format --- activesupport/lib/active_support/version.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'activesupport/lib/active_support') diff --git a/activesupport/lib/active_support/version.rb b/activesupport/lib/active_support/version.rb index 6c6187be29..831204693f 100644 --- a/activesupport/lib/active_support/version.rb +++ b/activesupport/lib/active_support/version.rb @@ -2,8 +2,9 @@ module ActiveSupport module VERSION #:nodoc: MAJOR = 3 MINOR = 0 - TINY = "0.beta1" + TINY = 0 + BUILD = "beta1" - STRING = [MAJOR, MINOR, TINY].join('.') + STRING = [MAJOR, MINOR, TINY, BUILD].join('.') end end -- cgit v1.2.3 From 6feffe5f38ad82d50b112ed102f8370ed934c8c1 Mon Sep 17 00:00:00 2001 From: windock Date: Wed, 3 Mar 2010 01:59:42 +0200 Subject: whiny nil shouldn't depend on Active Record [#4092 status:resolved] MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: José Valim --- activesupport/lib/active_support/whiny_nil.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activesupport/lib/active_support') diff --git a/activesupport/lib/active_support/whiny_nil.rb b/activesupport/lib/active_support/whiny_nil.rb index 11b05efac1..0b68e936f6 100644 --- a/activesupport/lib/active_support/whiny_nil.rb +++ b/activesupport/lib/active_support/whiny_nil.rb @@ -26,7 +26,7 @@ # mode. class NilClass WHINERS = [::Array] - WHINERS << ::ActiveRecord::Base if defined? ::ActiveRecord + WHINERS << ::ActiveRecord::Base if defined? ::ActiveRecord::Base METHOD_CLASS_MAP = Hash.new -- cgit v1.2.3 From f36a380c07186782a7c9e2c3d169b325ee8ab6dc Mon Sep 17 00:00:00 2001 From: Jason King Date: Fri, 26 Feb 2010 16:16:03 -0800 Subject: Inflection dependency, [#4067 status:resolved] MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: José Valim --- activesupport/lib/active_support/core_ext/string/inflections.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'activesupport/lib/active_support') diff --git a/activesupport/lib/active_support/core_ext/string/inflections.rb b/activesupport/lib/active_support/core_ext/string/inflections.rb index ea4ed61e42..fbb7b79fc6 100644 --- a/activesupport/lib/active_support/core_ext/string/inflections.rb +++ b/activesupport/lib/active_support/core_ext/string/inflections.rb @@ -1,8 +1,10 @@ +require 'active_support/inflector' + # String inflections define new methods on the String class to transform names for different purposes. # For instance, you can figure out the name of a database from the name of a class. # # "ScaleScore".tableize # => "scale_scores" - +# class String # Returns the plural form of the word in the string. # -- cgit v1.2.3 From 664090348154ccbf1274a13bbc3d3c37ba35bc7d Mon Sep 17 00:00:00 2001 From: Carlhuda Date: Tue, 2 Mar 2010 17:18:01 -0800 Subject: Move InheritableOptions into ActiveSupport --- activesupport/lib/active_support/ordered_options.rb | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'activesupport/lib/active_support') diff --git a/activesupport/lib/active_support/ordered_options.rb b/activesupport/lib/active_support/ordered_options.rb index 596a7b757d..61ccb79211 100644 --- a/activesupport/lib/active_support/ordered_options.rb +++ b/activesupport/lib/active_support/ordered_options.rb @@ -18,4 +18,10 @@ module ActiveSupport #:nodoc: end end end + + class InheritableOptions < OrderedOptions + def initialize(parent) + super() { |h,k| parent[k] } + end + end end -- cgit v1.2.3 From 8fc97d198ef31c1d7a4b9b849b96fc08a667fb02 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Fri, 5 Mar 2010 12:35:42 -0800 Subject: Allow deprecation messages with or without a final period. --- activesupport/lib/active_support/deprecation/reporting.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'activesupport/lib/active_support') diff --git a/activesupport/lib/active_support/deprecation/reporting.rb b/activesupport/lib/active_support/deprecation/reporting.rb index fcb05ad8d9..03c445ffbf 100644 --- a/activesupport/lib/active_support/deprecation/reporting.rb +++ b/activesupport/lib/active_support/deprecation/reporting.rb @@ -29,7 +29,8 @@ module ActiveSupport private def deprecation_message(callstack, message = nil) message ||= "You are using deprecated behavior which will be removed from the next major or minor release." - "DEPRECATION WARNING: #{message}. #{deprecation_caller_message(callstack)}" + message += '.' unless message =~ /\.$/ + "DEPRECATION WARNING: #{message} #{deprecation_caller_message(callstack)}" end def deprecation_caller_message(callstack) -- cgit v1.2.3 From 67512b9489593ddcd1c0c87ba0052380355b5400 Mon Sep 17 00:00:00 2001 From: Stijn Mathysen Date: Fri, 5 Mar 2010 08:04:25 +0100 Subject: Removed the + sign as an accepted character from the parameterize method, as a + sign is interpreted by the browser as a space, possibly resulting in a "ArgumentError: illegal character in key" [#4080 state:committed] Signed-off-by: Jeremy Kemper --- activesupport/lib/active_support/inflector/transliterate.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activesupport/lib/active_support') diff --git a/activesupport/lib/active_support/inflector/transliterate.rb b/activesupport/lib/active_support/inflector/transliterate.rb index 30a9072ee1..236f2eb628 100644 --- a/activesupport/lib/active_support/inflector/transliterate.rb +++ b/activesupport/lib/active_support/inflector/transliterate.rb @@ -47,7 +47,7 @@ module ActiveSupport # replace accented chars with their ascii equivalents parameterized_string = transliterate(string) # Turn unwanted chars into the separator - parameterized_string.gsub!(/[^a-z0-9\-_\+]+/i, sep) + parameterized_string.gsub!(/[^a-z0-9\-_]+/i, sep) unless sep.nil? || sep.empty? re_sep = Regexp.escape(sep) # No more than one of the separator in a row. -- cgit v1.2.3 From 39d6f9e112f2320d8c2006ee3bcc160cfa761d0a Mon Sep 17 00:00:00 2001 From: wycats Date: Sun, 7 Mar 2010 06:24:30 -0800 Subject: Make many parts of Rails lazy. In order to facilitate this, add lazy_load_hooks.rb, which allows us to declare code that should be run at some later time. For instance, this allows us to defer requiring ActiveRecord::Base at boot time purely to apply configuration. Instead, we register a hook that should apply configuration once ActiveRecord::Base is loaded. With these changes, brings down total boot time of a new app to 300ms in production and 400ms in dev. TODO: rename base_hook --- activesupport/lib/active_support/all.rb | 1 - .../active_support/core_ext/array/conversions.rb | 1 - .../core_ext/string/interpolation.rb | 92 +--------------------- .../lib/active_support/dependencies/autoload.rb | 5 ++ activesupport/lib/active_support/i18n.rb | 3 +- .../lib/active_support/lazy_load_hooks.rb | 25 ++++++ activesupport/lib/active_support/railtie.rb | 8 +- activesupport/lib/active_support/whiny_nil.rb | 7 +- 8 files changed, 41 insertions(+), 101 deletions(-) create mode 100644 activesupport/lib/active_support/lazy_load_hooks.rb (limited to 'activesupport/lib/active_support') diff --git a/activesupport/lib/active_support/all.rb b/activesupport/lib/active_support/all.rb index 64600575d9..f537818300 100644 --- a/activesupport/lib/active_support/all.rb +++ b/activesupport/lib/active_support/all.rb @@ -1,4 +1,3 @@ require 'active_support' -require 'active_support/i18n' require 'active_support/time' require 'active_support/core_ext' diff --git a/activesupport/lib/active_support/core_ext/array/conversions.rb b/activesupport/lib/active_support/core_ext/array/conversions.rb index 814567a5a6..2119322bfe 100644 --- a/activesupport/lib/active_support/core_ext/array/conversions.rb +++ b/activesupport/lib/active_support/core_ext/array/conversions.rb @@ -1,7 +1,6 @@ require 'active_support/core_ext/hash/keys' require 'active_support/core_ext/hash/reverse_merge' require 'active_support/inflector' -require 'active_support/i18n' class Array # Converts the array to a comma-separated sentence where the last element is joined by the connector word. Options: diff --git a/activesupport/lib/active_support/core_ext/string/interpolation.rb b/activesupport/lib/active_support/core_ext/string/interpolation.rb index 06d3505c60..932117cc10 100644 --- a/activesupport/lib/active_support/core_ext/string/interpolation.rb +++ b/activesupport/lib/active_support/core_ext/string/interpolation.rb @@ -1,91 +1 @@ -=begin - heavily based on Masao Mutoh's gettext String interpolation extension - http://github.com/mutoh/gettext/blob/f6566738b981fe0952548c421042ad1e0cdfb31e/lib/gettext/core_ext/string.rb - Copyright (C) 2005-2010 Masao Mutoh - You may redistribute it and/or modify it under the same license terms as Ruby. -=end - -if RUBY_VERSION < '1.9' && !"".respond_to?(:interpolate_without_ruby_19_syntax) - - # KeyError is raised by String#% when the string contains a named placeholder - # that is not contained in the given arguments hash. Ruby 1.9 includes and - # raises this exception natively. We define it to mimic Ruby 1.9's behaviour - # in Ruby 1.8.x - - class KeyError < IndexError - def initialize(message = nil) - super(message || "key not found") - end - end unless defined?(KeyError) - - # Extension for String class. This feature is included in Ruby 1.9 or later but not occur TypeError. - # - # String#% method which accept "named argument". The translator can know - # the meaning of the msgids using "named argument" instead of %s/%d style. - - class String - alias :interpolate_without_ruby_19_syntax :% # :nodoc: - - INTERPOLATION_PATTERN = Regexp.union( - /%%/, - /%\{(\w+)\}/, # matches placeholders like "%{foo}" - /%<(\w+)>(.*?\d*\.?\d*[bBdiouxXeEfgGcps])/ # matches placeholders like "%.d" - ) - - # % uses self (i.e. the String) as a format specification and returns the - # result of applying it to the given arguments. In other words it interpolates - # the given arguments to the string according to the formats the string - # defines. - # - # There are three ways to use it: - # - # * Using a single argument or Array of arguments. - # - # This is the default behaviour of the String class. See Kernel#sprintf for - # more details about the format string. - # - # Example: - # - # "%d %s" % [1, "message"] - # # => "1 message" - # - # * Using a Hash as an argument and unformatted, named placeholders. - # - # When you pass a Hash as an argument and specify placeholders with %{foo} - # it will interpret the hash values as named arguments. - # - # Example: - # - # "%{firstname}, %{lastname}" % {:firstname => "Masao", :lastname => "Mutoh"} - # # => "Masao Mutoh" - # - # * Using a Hash as an argument and formatted, named placeholders. - # - # When you pass a Hash as an argument and specify placeholders with %d - # it will interpret the hash values as named arguments and format the value - # according to the formatting instruction appended to the closing >. - # - # Example: - # - # "%d, %.1f" % { :integer => 10, :float => 43.4 } - # # => "10, 43.3" - def %(args) - if args.kind_of?(Hash) - dup.gsub(INTERPOLATION_PATTERN) do |match| - if match == '%%' - '%' - else - key = ($1 || $2).to_sym - raise KeyError unless args.has_key?(key) - $3 ? sprintf("%#{$3}", args[key]) : args[key] - end - end - elsif self =~ INTERPOLATION_PATTERN - raise ArgumentError.new('one hash required') - else - result = gsub(/%([{<])/, '%%\1') - result.send :'interpolate_without_ruby_19_syntax', args - end - end - end -end +require 'i18n/core_ext/string/interpolate' diff --git a/activesupport/lib/active_support/dependencies/autoload.rb b/activesupport/lib/active_support/dependencies/autoload.rb index 44edb89ad5..f669f4a77e 100644 --- a/activesupport/lib/active_support/dependencies/autoload.rb +++ b/activesupport/lib/active_support/dependencies/autoload.rb @@ -1,7 +1,12 @@ require "active_support/inflector/methods" +require "active_support/lazy_load_hooks" module ActiveSupport module Autoload + def self.extended(base) + base.extend(LazyLoadHooks) + end + @@autoloads = {} @@under_path = nil @@at_path = nil diff --git a/activesupport/lib/active_support/i18n.rb b/activesupport/lib/active_support/i18n.rb index 854c60eec1..034d7d8ddc 100644 --- a/activesupport/lib/active_support/i18n.rb +++ b/activesupport/lib/active_support/i18n.rb @@ -1,2 +1,3 @@ require 'i18n' -I18n.load_path << "#{File.dirname(__FILE__)}/locale/en.yml" \ No newline at end of file +I18n.load_path << "#{File.dirname(__FILE__)}/locale/en.yml" +ActiveSupport.run_base_hooks(:i18n) \ No newline at end of file diff --git a/activesupport/lib/active_support/lazy_load_hooks.rb b/activesupport/lib/active_support/lazy_load_hooks.rb new file mode 100644 index 0000000000..36acfda524 --- /dev/null +++ b/activesupport/lib/active_support/lazy_load_hooks.rb @@ -0,0 +1,25 @@ +module ActiveSupport + module LazyLoadHooks + def _setup_base_hooks + @base_hooks ||= Hash.new {|h,k| h[k] = [] } + @base ||= {} + end + + def base_hook(name = nil, &block) + _setup_base_hooks + + if base = @base[name] + base.instance_eval(&block) + else + @base_hooks[name] << block + end + end + + def run_base_hooks(base, name = nil) + _setup_base_hooks + + @base_hooks[name].each { |hook| base.instance_eval(&hook) } if @base_hooks + @base[name] = base + end + end +end \ No newline at end of file diff --git a/activesupport/lib/active_support/railtie.rb b/activesupport/lib/active_support/railtie.rb index 58d11585ba..d2c13e030d 100644 --- a/activesupport/lib/active_support/railtie.rb +++ b/activesupport/lib/active_support/railtie.rb @@ -37,10 +37,12 @@ module I18n config.i18n.load_path = [] initializer "i18n.initialize" do - require 'active_support/i18n' - - ActionDispatch::Callbacks.to_prepare do + ActiveSupport.base_hook(:i18n) do I18n.reload! + + ActionDispatch::Callbacks.to_prepare do + I18n.reload! + end end end diff --git a/activesupport/lib/active_support/whiny_nil.rb b/activesupport/lib/active_support/whiny_nil.rb index 0b68e936f6..91ddef2619 100644 --- a/activesupport/lib/active_support/whiny_nil.rb +++ b/activesupport/lib/active_support/whiny_nil.rb @@ -25,17 +25,16 @@ # By default it is on in development and test modes, and it is off in production # mode. class NilClass - WHINERS = [::Array] - WHINERS << ::ActiveRecord::Base if defined? ::ActiveRecord::Base - METHOD_CLASS_MAP = Hash.new - WHINERS.each do |klass| + def self.add_whiner(klass) methods = klass.public_instance_methods - public_instance_methods class_name = klass.name methods.each { |method| METHOD_CLASS_MAP[method.to_sym] = class_name } end + add_whiner ::Array + # Raises a RuntimeError when you attempt to call +id+ on +nil+. def id raise RuntimeError, "Called id for nil, which would mistakenly be 4 -- if you really wanted the id of nil, use object_id", caller -- cgit v1.2.3 From 60bbf16bfd60493c05bf9c9c70ec962a0c482155 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Mon, 8 Mar 2010 16:08:46 -0800 Subject: class_attribute gets instance methods which delegate to but may override their class values as you'd expect. Disable instance writer methods with :instance_writer => false. --- .../lib/active_support/core_ext/class/attribute.rb | 25 ++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'activesupport/lib/active_support') diff --git a/activesupport/lib/active_support/core_ext/class/attribute.rb b/activesupport/lib/active_support/core_ext/class/attribute.rb index 1bd39a9349..c18905b369 100644 --- a/activesupport/lib/active_support/core_ext/class/attribute.rb +++ b/activesupport/lib/active_support/core_ext/class/attribute.rb @@ -24,14 +24,35 @@ class Class # For convenience, a query method is defined as well: # # Subclass.setting? # => false + # + # Instances may overwrite the class value in the same way: + # + # Base.setting = true + # object = Base.new + # object.setting # => true + # object.setting = false + # object.setting # => false + # Base.setting # => true + # + # To opt out of the instance writer method, pass :instance_writer => false. + # + # object.setting = false # => NoMethodError def class_attribute(*attrs) + instance_writer = !attrs.last.is_a?(Hash) || attrs.pop[:instance_writer] + s = singleton_class attrs.each do |attr| s.send(:define_method, attr) { } - s.send(:define_method, "#{attr}?") { !!send(attr) } - s.send(:define_method, "#{attr}=") do |value| + s.send(:define_method, :"#{attr}?") { !!send(attr) } + s.send(:define_method, :"#{attr}=") do |value| singleton_class.send(:define_method, attr) { value } end + + define_method(attr) { self.class.send(attr) } + define_method(:"#{attr}?") { !!send(attr) } + define_method(:"#{attr}=") do |value| + singleton_class.send(:define_method, attr) { value } + end if instance_writer end end end -- cgit v1.2.3 From a87683fb38d6cf66f39a7bd3faa6c969c63b1f46 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Tue, 9 Mar 2010 11:06:31 -0800 Subject: Disprefer JSONGem decoder since it only decodes JSON objects --- activesupport/lib/active_support/json/decoding.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activesupport/lib/active_support') diff --git a/activesupport/lib/active_support/json/decoding.rb b/activesupport/lib/active_support/json/decoding.rb index e357b6837a..04ff316a44 100644 --- a/activesupport/lib/active_support/json/decoding.rb +++ b/activesupport/lib/active_support/json/decoding.rb @@ -7,7 +7,7 @@ module ActiveSupport module JSON # Listed in order of preference. - DECODERS = %w(Yajl JSONGem Yaml) + DECODERS = %w(Yajl Yaml) class << self attr_reader :parse_error -- cgit v1.2.3 From 1f6c5677ad18a2d49866100b043b82bd030875d4 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Thu, 11 Mar 2010 17:08:33 -0800 Subject: OutputBuffer#to_yaml should return string yaml, not some custom class dump --- activesupport/lib/active_support/core_ext/string/output_safety.rb | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'activesupport/lib/active_support') diff --git a/activesupport/lib/active_support/core_ext/string/output_safety.rb b/activesupport/lib/active_support/core_ext/string/output_safety.rb index 567ba00b0d..c55b471986 100644 --- a/activesupport/lib/active_support/core_ext/string/output_safety.rb +++ b/activesupport/lib/active_support/core_ext/string/output_safety.rb @@ -88,6 +88,10 @@ module ActiveSupport #:nodoc: def to_s self end + + def to_yaml + "".replace(self).to_yaml + end end end -- cgit v1.2.3 From 47bc138fc1d9ddafab8e4cf9cac8865f2092c003 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Thu, 11 Mar 2010 17:32:26 -0800 Subject: Write strings to fragment cache, not outputbuffers --- activesupport/lib/active_support/core_ext/string/output_safety.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'activesupport/lib/active_support') diff --git a/activesupport/lib/active_support/core_ext/string/output_safety.rb b/activesupport/lib/active_support/core_ext/string/output_safety.rb index c55b471986..3a49cd288b 100644 --- a/activesupport/lib/active_support/core_ext/string/output_safety.rb +++ b/activesupport/lib/active_support/core_ext/string/output_safety.rb @@ -89,8 +89,12 @@ module ActiveSupport #:nodoc: self end + def as_str + ''.replace(self) + end + def to_yaml - "".replace(self).to_yaml + as_str.to_yaml end end end -- cgit v1.2.3 From f10631e13d373523c1ede9c73a5d7eb2e0529a27 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Thu, 11 Mar 2010 18:37:28 -0800 Subject: Be sure to pass through args to to_yaml --- activesupport/lib/active_support/core_ext/string/output_safety.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'activesupport/lib/active_support') diff --git a/activesupport/lib/active_support/core_ext/string/output_safety.rb b/activesupport/lib/active_support/core_ext/string/output_safety.rb index 3a49cd288b..af46ae10d6 100644 --- a/activesupport/lib/active_support/core_ext/string/output_safety.rb +++ b/activesupport/lib/active_support/core_ext/string/output_safety.rb @@ -93,8 +93,8 @@ module ActiveSupport #:nodoc: ''.replace(self) end - def to_yaml - as_str.to_yaml + def to_yaml(*args) + as_str.to_yaml(*args) end end end -- cgit v1.2.3