Permalink
Browse files

Rails 3: move core_ext/blank to core_ext/object/blank for forward com…

…patibility
  • Loading branch information...
1 parent 93085a7 commit 0bc150c884e9840fb6e917a818312eab3da83300 @jeremy jeremy committed Nov 22, 2009
@@ -1,4 +1,8 @@
-Dir[File.dirname(__FILE__) + "/core_ext/*.rb"].sort.each do |path|
- filename = File.basename(path, '.rb')
- require "active_support/core_ext/#{filename}"
+filenames = Dir["#{File.dirname(__FILE__)}/core_ext/*.rb"].sort.map do |path|
+ File.basename(path, '.rb')
end
+
+# deprecated
+filenames -= %w(blank)
+
+filenames.each { |filename| require "active_support/core_ext/#{filename}" }
@@ -1,58 +1,2 @@
-class Object
- # An object is blank if it's false, empty, or a whitespace string.
- # For example, "", " ", +nil+, [], and {} are blank.
- #
- # This simplifies
- #
- # if !address.nil? && !address.empty?
- #
- # to
- #
- # if !address.blank?
- def blank?
- respond_to?(:empty?) ? empty? : !self
- end
-
- # An object is present if it's not blank.
- def present?
- !blank?
- end
-end
-
-class NilClass #:nodoc:
- def blank?
- true
- end
-end
-
-class FalseClass #:nodoc:
- def blank?
- true
- end
-end
-
-class TrueClass #:nodoc:
- def blank?
- false
- end
-end
-
-class Array #:nodoc:
- alias_method :blank?, :empty?
-end
-
-class Hash #:nodoc:
- alias_method :blank?, :empty?
-end
-
-class String #:nodoc:
- def blank?
- self !~ /\S/
- end
-end
-
-class Numeric #:nodoc:
- def blank?
- false
- end
-end
+require 'active_support/core_ext/object/blank'
+ActiveSupport::Deprecation.warn 'require "active_support/core_ext/blank" is deprecated and will be removed in Rails 3. Use require "active_support/core_ext/object/blank" instead.'
@@ -1,3 +1,4 @@
+require 'active_support/core_ext/object/blank'
require 'active_support/core_ext/object/conversions'
require 'active_support/core_ext/object/extending'
require 'active_support/core_ext/object/instance_variables'
@@ -0,0 +1,58 @@
+class Object
+ # An object is blank if it's false, empty, or a whitespace string.
+ # For example, "", " ", +nil+, [], and {} are blank.
+ #
+ # This simplifies
+ #
+ # if !address.nil? && !address.empty?
+ #
+ # to
+ #
+ # if !address.blank?
+ def blank?
+ respond_to?(:empty?) ? empty? : !self
+ end
+
+ # An object is present if it's not blank.
+ def present?
+ !blank?
+ end
+end
+
+class NilClass #:nodoc:
+ def blank?
+ true
+ end
+end
+
+class FalseClass #:nodoc:
+ def blank?
+ true
+ end
+end
+
+class TrueClass #:nodoc:
+ def blank?
+ false
+ end
+end
+
+class Array #:nodoc:
+ alias_method :blank?, :empty?
+end
+
+class Hash #:nodoc:
+ alias_method :blank?, :empty?
+end
+
+class String #:nodoc:
+ def blank?
+ self !~ /\S/
+ end
+end
+
+class Numeric #:nodoc:
+ def blank?
+ false
+ end
+end

0 comments on commit 0bc150c

Please sign in to comment.