From c65f4b1ffb3862909df7c883f3486e08425bdc6a Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Thu, 4 Feb 2010 09:54:54 -0200 Subject: Making SafeBuffer << an alias for concat method [#3848 state:committed] Signed-off-by: Jeremy Kemper --- activesupport/lib/active_support/core_ext/string/output_safety.rb | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'activesupport/lib/active_support/core_ext') 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 3977971e8d..567ba00b0d 100644 --- a/activesupport/lib/active_support/core_ext/string/output_safety.rb +++ b/activesupport/lib/active_support/core_ext/string/output_safety.rb @@ -71,15 +71,12 @@ module ActiveSupport #:nodoc: super(ERB::Util.h(value)) end end + alias << concat def +(other) dup.concat(other) end - def <<(value) - self.concat(value) - end - def html_safe? true end @@ -102,4 +99,4 @@ class String def html_safe ActiveSupport::SafeBuffer.new(self) end -end \ No newline at end of file +end -- cgit v1.2.3 From 299ab1faa18f88e6f2b9a4724f9009109e86949e Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Sat, 6 Feb 2010 18:33:09 +0100 Subject: removes Kernel#daemonize, which is no longer used --- activesupport/lib/active_support/core_ext/kernel.rb | 1 - activesupport/lib/active_support/core_ext/kernel/daemonizing.rb | 7 ------- 2 files changed, 8 deletions(-) delete mode 100644 activesupport/lib/active_support/core_ext/kernel/daemonizing.rb (limited to 'activesupport/lib/active_support/core_ext') diff --git a/activesupport/lib/active_support/core_ext/kernel.rb b/activesupport/lib/active_support/core_ext/kernel.rb index 1922d804bf..c3bed14f63 100644 --- a/activesupport/lib/active_support/core_ext/kernel.rb +++ b/activesupport/lib/active_support/core_ext/kernel.rb @@ -1,4 +1,3 @@ -require 'active_support/core_ext/kernel/daemonizing' require 'active_support/core_ext/kernel/reporting' require 'active_support/core_ext/kernel/agnostics' require 'active_support/core_ext/kernel/requires' diff --git a/activesupport/lib/active_support/core_ext/kernel/daemonizing.rb b/activesupport/lib/active_support/core_ext/kernel/daemonizing.rb deleted file mode 100644 index ed9d1f9bf2..0000000000 --- a/activesupport/lib/active_support/core_ext/kernel/daemonizing.rb +++ /dev/null @@ -1,7 +0,0 @@ -module Kernel - # Turns the current script into a daemon process that detaches from the console. - # It can be shut down with a TERM signal. - def daemonize - Process.daemon - end -end -- cgit v1.2.3 From f44a0b1d524064a2e919cd10d3013db680af9b17 Mon Sep 17 00:00:00 2001 From: RomD Date: Sat, 6 Feb 2010 17:18:10 +0100 Subject: fix usage examples and more to use new invocations Signed-off-by: Carl Lerche --- activesupport/lib/active_support/core_ext/kernel/debugger.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activesupport/lib/active_support/core_ext') diff --git a/activesupport/lib/active_support/core_ext/kernel/debugger.rb b/activesupport/lib/active_support/core_ext/kernel/debugger.rb index 59e03e3df7..22fcc1910b 100644 --- a/activesupport/lib/active_support/core_ext/kernel/debugger.rb +++ b/activesupport/lib/active_support/core_ext/kernel/debugger.rb @@ -1,6 +1,6 @@ module Kernel unless respond_to?(:debugger) - # Starts a debugging session if ruby-debug has been loaded (call script/server --debugger to do load it). + # Starts a debugging session if ruby-debug has been loaded (call rails server --debugger to do load it). def debugger message = "\n***** Debugger requested, but was not available: Start server with --debugger to enable *****\n" defined?(Rails) ? Rails.logger.info(message) : $stderr.puts(message) -- cgit v1.2.3 From a1a6e54d14b70e1d418d4939328e6eb24bdd8f3b Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Sun, 7 Feb 2010 11:41:49 -0800 Subject: Fix doc typo and update fast_xs URL. Thanks to Dmitrii Golub. --- activesupport/lib/active_support/core_ext/file/atomic.rb | 2 +- activesupport/lib/active_support/core_ext/string/xchar.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'activesupport/lib/active_support/core_ext') diff --git a/activesupport/lib/active_support/core_ext/file/atomic.rb b/activesupport/lib/active_support/core_ext/file/atomic.rb index 249fb1362d..49d28e8a34 100644 --- a/activesupport/lib/active_support/core_ext/file/atomic.rb +++ b/activesupport/lib/active_support/core_ext/file/atomic.rb @@ -9,7 +9,7 @@ class File # If your temp directory is not on the same filesystem as the file you're # trying to write, you can provide a different temporary directory. # - # File.atomic_write("/data/something.important", "/data/tmp") do |f| + # File.atomic_write("/data/something.important", "/data/tmp") do |file| # file.write("hello") # end def self.atomic_write(file_name, temp_dir = Dir.tmpdir) diff --git a/activesupport/lib/active_support/core_ext/string/xchar.rb b/activesupport/lib/active_support/core_ext/string/xchar.rb index 7183218634..f9a5b4fb64 100644 --- a/activesupport/lib/active_support/core_ext/string/xchar.rb +++ b/activesupport/lib/active_support/core_ext/string/xchar.rb @@ -1,5 +1,5 @@ begin - # See http://bogomips.org/fast_xs/ by Eric Wong. + # See http://fast-xs.rubyforge.org/ by Eric Wong. # Also included with hpricot. require 'fast_xs' rescue LoadError -- cgit v1.2.3 From afd2e19be3b74effa3fdb9c4affd48f0aaede838 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Sun, 7 Feb 2010 23:03:13 +0100 Subject: removes Module#included_in_classes, which is no longer used --- .../lib/active_support/core_ext/module.rb | 1 - .../active_support/core_ext/module/inclusion.rb | 30 ---------------------- 2 files changed, 31 deletions(-) delete mode 100644 activesupport/lib/active_support/core_ext/module/inclusion.rb (limited to 'activesupport/lib/active_support/core_ext') diff --git a/activesupport/lib/active_support/core_ext/module.rb b/activesupport/lib/active_support/core_ext/module.rb index fbe89fe07c..b9c9614ca6 100644 --- a/activesupport/lib/active_support/core_ext/module.rb +++ b/activesupport/lib/active_support/core_ext/module.rb @@ -1,7 +1,6 @@ require 'active_support/core_ext/module/aliasing' require 'active_support/core_ext/module/introspection' -require 'active_support/core_ext/module/inclusion' require 'active_support/core_ext/module/attribute_accessors' require 'active_support/core_ext/module/attr_internal' require 'active_support/core_ext/module/attr_accessor_with_default' diff --git a/activesupport/lib/active_support/core_ext/module/inclusion.rb b/activesupport/lib/active_support/core_ext/module/inclusion.rb deleted file mode 100644 index 4f23841645..0000000000 --- a/activesupport/lib/active_support/core_ext/module/inclusion.rb +++ /dev/null @@ -1,30 +0,0 @@ -class Module - # Returns the classes in the current ObjectSpace where this module has been - # mixed in according to Module#included_modules. - # - # module M - # end - # - # module N - # include M - # end - # - # class C - # include M - # end - # - # class D < C - # end - # - # p M.included_in_classes # => [C, D] - # - def included_in_classes - classes = [] - ObjectSpace.each_object(Class) { |k| classes << k if k.included_modules.include?(self) } - - classes.reverse.inject([]) do |unique_classes, klass| - unique_classes << klass unless unique_classes.collect { |k| k.to_s }.include?(klass.to_s) - unique_classes - end - end -end \ No newline at end of file -- cgit v1.2.3 From cf9a52a7b6a4cb28709f116b306e06395b40b752 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Sun, 7 Feb 2010 23:06:15 +0100 Subject: removes Module#as_load_path, which is no longer used --- .../lib/active_support/core_ext/module.rb | 1 - .../lib/active_support/core_ext/module/loading.rb | 25 ---------------------- 2 files changed, 26 deletions(-) delete mode 100644 activesupport/lib/active_support/core_ext/module/loading.rb (limited to 'activesupport/lib/active_support/core_ext') diff --git a/activesupport/lib/active_support/core_ext/module.rb b/activesupport/lib/active_support/core_ext/module.rb index b9c9614ca6..41600929f4 100644 --- a/activesupport/lib/active_support/core_ext/module.rb +++ b/activesupport/lib/active_support/core_ext/module.rb @@ -5,5 +5,4 @@ require 'active_support/core_ext/module/attribute_accessors' require 'active_support/core_ext/module/attr_internal' require 'active_support/core_ext/module/attr_accessor_with_default' require 'active_support/core_ext/module/delegation' -require 'active_support/core_ext/module/loading' require 'active_support/core_ext/module/synchronization' diff --git a/activesupport/lib/active_support/core_ext/module/loading.rb b/activesupport/lib/active_support/core_ext/module/loading.rb deleted file mode 100644 index 43d0578ae6..0000000000 --- a/activesupport/lib/active_support/core_ext/module/loading.rb +++ /dev/null @@ -1,25 +0,0 @@ -require 'active_support/core_ext/string/inflections' - -class Module - # Returns String#underscore applied to the module name minus trailing classes. - # - # ActiveRecord.as_load_path # => "active_record" - # ActiveRecord::Associations.as_load_path # => "active_record/associations" - # ActiveRecord::Base.as_load_path # => "active_record" (Base is a class) - # - # The Kernel module gives an empty string by definition. - # - # Kernel.as_load_path # => "" - # Math.as_load_path # => "math" - def as_load_path - if self == Object || self == Kernel - '' - elsif is_a? Class - parent == self ? '' : parent.as_load_path - else - name.split('::').collect do |word| - word.underscore - end * '/' - end - end -end \ No newline at end of file -- cgit v1.2.3 From d1938953f416ac945b591251567d51e30ee2a6a4 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Tue, 9 Feb 2010 18:03:14 -0800 Subject: Reinstate Object.subclasses_of and Class#descendents for plugin compat. This reverts commits 7d312e54bad9c39634c137caec07dfc8df471650, 5f981ff0294ba45aa44ad15aa063970b29aeec44, f85f5dfc8ffefff174b695c6363211d342f77a57, 245bfafe335ff883f7a096eab95ac22fe2848679, and ec7c642f5fe60afc857aa64f1a9b4c2be56f9d70 --- activesupport/lib/active_support/core_ext/class.rb | 1 + .../active_support/core_ext/class/subclasses.rb | 58 ++++++++++++++++++++++ .../active_support/core_ext/object/extending.rb | 11 ++++ 3 files changed, 70 insertions(+) create mode 100644 activesupport/lib/active_support/core_ext/class/subclasses.rb create mode 100644 activesupport/lib/active_support/core_ext/object/extending.rb (limited to 'activesupport/lib/active_support/core_ext') diff --git a/activesupport/lib/active_support/core_ext/class.rb b/activesupport/lib/active_support/core_ext/class.rb index 62df7d8b82..f2ca9c7cc9 100644 --- a/activesupport/lib/active_support/core_ext/class.rb +++ b/activesupport/lib/active_support/core_ext/class.rb @@ -1,3 +1,4 @@ require 'active_support/core_ext/class/attribute_accessors' require 'active_support/core_ext/class/inheritable_attributes' require 'active_support/core_ext/class/delegating_attributes' +require 'active_support/core_ext/class/subclasses' diff --git a/activesupport/lib/active_support/core_ext/class/subclasses.rb b/activesupport/lib/active_support/core_ext/class/subclasses.rb new file mode 100644 index 0000000000..c166ce8079 --- /dev/null +++ b/activesupport/lib/active_support/core_ext/class/subclasses.rb @@ -0,0 +1,58 @@ +require 'active_support/core_ext/object/blank' + +class Class #:nodoc: + # Returns an array with the names of the subclasses of +self+ as strings. + # + # Integer.subclasses # => ["Bignum", "Fixnum"] + def subclasses + Class.subclasses_of(self).map { |o| o.to_s } + end + + def reachable? #:nodoc: + eval("defined?(::#{self}) && ::#{self}.equal?(self)") + end + + # Rubinius + if defined?(Class.__subclasses__) + def descendents + subclasses = [] + __subclasses__.each {|k| subclasses << k; subclasses.concat k.descendents } + subclasses + end + else + # MRI + begin + ObjectSpace.each_object(Class.new) {} + + def descendents + subclasses = [] + ObjectSpace.each_object(class << self; self; end) do |k| + subclasses << k unless k == self + end + subclasses + end + # JRuby + rescue StandardError + def descendents + subclasses = [] + ObjectSpace.each_object(Class) do |k| + subclasses << k if k < self + end + subclasses.uniq! + subclasses + end + end + end + + # Exclude this class unless it's a subclass of our supers and is defined. + # We check defined? in case we find a removed class that has yet to be + # garbage collected. This also fails for anonymous classes -- please + # submit a patch if you have a workaround. + def self.subclasses_of(*superclasses) #:nodoc: + subclasses = [] + superclasses.each do |klass| + subclasses.concat klass.descendents.select {|k| k.name.blank? || k.reachable?} + end + subclasses + end +end diff --git a/activesupport/lib/active_support/core_ext/object/extending.rb b/activesupport/lib/active_support/core_ext/object/extending.rb new file mode 100644 index 0000000000..c4c37b6a2a --- /dev/null +++ b/activesupport/lib/active_support/core_ext/object/extending.rb @@ -0,0 +1,11 @@ +require 'active_support/core_ext/class/subclasses' + +class Object + # Exclude this class unless it's a subclass of our supers and is defined. + # We check defined? in case we find a removed class that has yet to be + # garbage collected. This also fails for anonymous classes -- please + # submit a patch if you have a workaround. + def subclasses_of(*superclasses) #:nodoc: + Class.subclasses_of(*superclasses) + end +end -- cgit v1.2.3 From f84b4b4e5f1c626460d147d9ad9cf1d712514af5 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Tue, 9 Feb 2010 19:42:08 -0800 Subject: Reinstate object/extending require too for Object.subclasses_of --- activesupport/lib/active_support/core_ext/object.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'activesupport/lib/active_support/core_ext') diff --git a/activesupport/lib/active_support/core_ext/object.rb b/activesupport/lib/active_support/core_ext/object.rb index 08e07a5b24..46bbbff88a 100644 --- a/activesupport/lib/active_support/core_ext/object.rb +++ b/activesupport/lib/active_support/core_ext/object.rb @@ -7,3 +7,4 @@ 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/misc' +require 'active_support/core_ext/object/extending' -- cgit v1.2.3 From b8bb54af7ff6652327d99f6a7cf5c96a3f3f876d Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Thu, 11 Feb 2010 23:15:04 +0100 Subject: defines Module#anonymous? --- activesupport/lib/active_support/core_ext/module.rb | 2 +- .../lib/active_support/core_ext/module/anonymous.rb | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 activesupport/lib/active_support/core_ext/module/anonymous.rb (limited to 'activesupport/lib/active_support/core_ext') diff --git a/activesupport/lib/active_support/core_ext/module.rb b/activesupport/lib/active_support/core_ext/module.rb index 41600929f4..c907445d90 100644 --- a/activesupport/lib/active_support/core_ext/module.rb +++ b/activesupport/lib/active_support/core_ext/module.rb @@ -1,6 +1,6 @@ require 'active_support/core_ext/module/aliasing' require 'active_support/core_ext/module/introspection' - +require 'active_support/core_ext/module/anonymous' require 'active_support/core_ext/module/attribute_accessors' require 'active_support/core_ext/module/attr_internal' require 'active_support/core_ext/module/attr_accessor_with_default' diff --git a/activesupport/lib/active_support/core_ext/module/anonymous.rb b/activesupport/lib/active_support/core_ext/module/anonymous.rb new file mode 100644 index 0000000000..60d7d9410b --- /dev/null +++ b/activesupport/lib/active_support/core_ext/module/anonymous.rb @@ -0,0 +1,20 @@ +class Module + # A module may or may not have a name. + # + # module M; end + # M.name # => "M" + # + # m = Module.new + # m.name # => "" + # + # A module gets a name when it is first assigned to a constant. Either + # via the +module+ or +class+ keyword or by an explicit assignment: + # + # m = Module.new # creates an anonymous module + # M = m # => m gets a name here as a side-effect + # m.name # => "M" + # + def anonymous? + name == '' + end +end -- cgit v1.2.3 From aa82bdf92953824fd35db4a734bf6effa8de3329 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Thu, 11 Feb 2010 23:41:16 +0100 Subject: moves Class#reachable? to Module#reachable?, bases implementation on anonymous? and constantize, and adds test coverage --- activesupport/lib/active_support/core_ext/class/subclasses.rb | 9 +++------ activesupport/lib/active_support/core_ext/module.rb | 1 + activesupport/lib/active_support/core_ext/module/reachable.rb | 10 ++++++++++ 3 files changed, 14 insertions(+), 6 deletions(-) create mode 100644 activesupport/lib/active_support/core_ext/module/reachable.rb (limited to 'activesupport/lib/active_support/core_ext') diff --git a/activesupport/lib/active_support/core_ext/class/subclasses.rb b/activesupport/lib/active_support/core_ext/class/subclasses.rb index c166ce8079..bbd8f5aef6 100644 --- a/activesupport/lib/active_support/core_ext/class/subclasses.rb +++ b/activesupport/lib/active_support/core_ext/class/subclasses.rb @@ -1,4 +1,5 @@ -require 'active_support/core_ext/object/blank' +require 'active_support/core_ext/module/anonymous' +require 'active_support/core_ext/module/reachable' class Class #:nodoc: # Returns an array with the names of the subclasses of +self+ as strings. @@ -8,10 +9,6 @@ class Class #:nodoc: Class.subclasses_of(self).map { |o| o.to_s } end - def reachable? #:nodoc: - eval("defined?(::#{self}) && ::#{self}.equal?(self)") - end - # Rubinius if defined?(Class.__subclasses__) def descendents @@ -51,7 +48,7 @@ class Class #:nodoc: def self.subclasses_of(*superclasses) #:nodoc: subclasses = [] superclasses.each do |klass| - subclasses.concat klass.descendents.select {|k| k.name.blank? || k.reachable?} + subclasses.concat klass.descendents.select {|k| k.anonymous? || k.reachable?} end subclasses end diff --git a/activesupport/lib/active_support/core_ext/module.rb b/activesupport/lib/active_support/core_ext/module.rb index c907445d90..07bac29a9f 100644 --- a/activesupport/lib/active_support/core_ext/module.rb +++ b/activesupport/lib/active_support/core_ext/module.rb @@ -1,6 +1,7 @@ require 'active_support/core_ext/module/aliasing' require 'active_support/core_ext/module/introspection' require 'active_support/core_ext/module/anonymous' +require 'active_support/core_ext/module/reachable' require 'active_support/core_ext/module/attribute_accessors' require 'active_support/core_ext/module/attr_internal' require 'active_support/core_ext/module/attr_accessor_with_default' diff --git a/activesupport/lib/active_support/core_ext/module/reachable.rb b/activesupport/lib/active_support/core_ext/module/reachable.rb new file mode 100644 index 0000000000..443d2c3d53 --- /dev/null +++ b/activesupport/lib/active_support/core_ext/module/reachable.rb @@ -0,0 +1,10 @@ +require 'active_support/core_ext/module/anonymous' +require 'active_support/core_ext/string/inflections' + +class Module + def reachable? #:nodoc: + !anonymous? && name.constantize.equal?(self) + rescue NameError + false + end +end -- cgit v1.2.3 From a506bac58616db2dc2b470a2416deed398645916 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Thu, 11 Feb 2010 23:58:15 +0100 Subject: fixes Module#anonymous? for 1.9 --- activesupport/lib/active_support/core_ext/module/anonymous.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'activesupport/lib/active_support/core_ext') diff --git a/activesupport/lib/active_support/core_ext/module/anonymous.rb b/activesupport/lib/active_support/core_ext/module/anonymous.rb index 60d7d9410b..df25a09ec9 100644 --- a/activesupport/lib/active_support/core_ext/module/anonymous.rb +++ b/activesupport/lib/active_support/core_ext/module/anonymous.rb @@ -1,4 +1,6 @@ -class Module +require 'active_support/core_ext/object/blank' + +class Module # A module may or may not have a name. # # module M; end @@ -15,6 +17,8 @@ class Module # m.name # => "M" # def anonymous? - name == '' + # Uses blank? because the name of an anonymous class is an empty + # string in 1.8, and nil in 1.9. + name.blank? end end -- cgit v1.2.3 From f7db067b128b6e78b3296b5924ff65a8ba732e1c Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Sun, 14 Feb 2010 20:01:33 +0100 Subject: adds a few missing requires in AS object.rb and module.rb Signed-off-by: Yehuda Katz --- activesupport/lib/active_support/core_ext/module.rb | 1 + activesupport/lib/active_support/core_ext/object.rb | 5 +++++ 2 files changed, 6 insertions(+) (limited to 'activesupport/lib/active_support/core_ext') diff --git a/activesupport/lib/active_support/core_ext/module.rb b/activesupport/lib/active_support/core_ext/module.rb index 07bac29a9f..bf272e9e73 100644 --- a/activesupport/lib/active_support/core_ext/module.rb +++ b/activesupport/lib/active_support/core_ext/module.rb @@ -7,3 +7,4 @@ require 'active_support/core_ext/module/attr_internal' require 'active_support/core_ext/module/attr_accessor_with_default' require 'active_support/core_ext/module/delegation' require 'active_support/core_ext/module/synchronization' +require 'active_support/core_ext/module/deprecation' \ No newline at end of file diff --git a/activesupport/lib/active_support/core_ext/object.rb b/activesupport/lib/active_support/core_ext/object.rb index 46bbbff88a..db2dac1472 100644 --- a/activesupport/lib/active_support/core_ext/object.rb +++ b/activesupport/lib/active_support/core_ext/object.rb @@ -8,3 +8,8 @@ require 'active_support/core_ext/object/instance_variables' require 'active_support/core_ext/object/metaclass' require 'active_support/core_ext/object/misc' require 'active_support/core_ext/object/extending' + +require 'active_support/core_ext/object/returning' +require 'active_support/core_ext/object/to_param' +require 'active_support/core_ext/object/to_query' +require 'active_support/core_ext/object/with_options' -- cgit v1.2.3