diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2005-02-15 15:57:44 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2005-02-15 15:57:44 +0000 |
commit | dc3d6eb9b4aaed051dd6d5a5a07f6c66b72da4c4 (patch) | |
tree | 1d77afa3e7a5af3d3d89c2121b5cecf6423d666d /activesupport/lib/core_ext | |
parent | 45caae41c3fbfc7ba77c5e2dc70734fa80501828 (diff) | |
download | rails-dc3d6eb9b4aaed051dd6d5a5a07f6c66b72da4c4.tar.gz rails-dc3d6eb9b4aaed051dd6d5a5a07f6c66b72da4c4.tar.bz2 rails-dc3d6eb9b4aaed051dd6d5a5a07f6c66b72da4c4.zip |
Moved Active Support into its own gem
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@624 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activesupport/lib/core_ext')
-rw-r--r-- | activesupport/lib/core_ext/hash.rb | 7 | ||||
-rw-r--r-- | activesupport/lib/core_ext/hash/indifferent_access.rb | 38 | ||||
-rw-r--r-- | activesupport/lib/core_ext/hash/keys.rb | 53 | ||||
-rw-r--r-- | activesupport/lib/core_ext/numeric.rb | 7 | ||||
-rw-r--r-- | activesupport/lib/core_ext/numeric/bytes.rb | 33 | ||||
-rw-r--r-- | activesupport/lib/core_ext/numeric/time.rb | 59 | ||||
-rw-r--r-- | activesupport/lib/core_ext/object_and_class.rb | 24 | ||||
-rw-r--r-- | activesupport/lib/core_ext/string.rb | 5 | ||||
-rw-r--r-- | activesupport/lib/core_ext/string/inflections.rb | 49 |
9 files changed, 0 insertions, 275 deletions
diff --git a/activesupport/lib/core_ext/hash.rb b/activesupport/lib/core_ext/hash.rb deleted file mode 100644 index e899d3e1e2..0000000000 --- a/activesupport/lib/core_ext/hash.rb +++ /dev/null @@ -1,7 +0,0 @@ -require File.dirname(__FILE__) + '/hash/keys' -require File.dirname(__FILE__) + '/hash/indifferent_access' - -class Hash #:nodoc: - include ActiveSupport::CoreExtensions::Hash::Keys - include ActiveSupport::CoreExtensions::Hash::IndifferentAccess -end diff --git a/activesupport/lib/core_ext/hash/indifferent_access.rb b/activesupport/lib/core_ext/hash/indifferent_access.rb deleted file mode 100644 index 2353cfaf3b..0000000000 --- a/activesupport/lib/core_ext/hash/indifferent_access.rb +++ /dev/null @@ -1,38 +0,0 @@ -class HashWithIndifferentAccess < Hash - def initialize(constructor) - if constructor.is_a?(Hash) - super() - update(constructor.symbolize_keys) - else - super(constructor) - end - end - - alias_method :regular_reader, :[] unless method_defined?(:regular_reader) - - def [](key) - case key - when Symbol: regular_reader(key) || regular_reader(key.to_s) - when String: regular_reader(key) || regular_reader(key.to_sym) - else regular_reader(key) - end - end - - alias_method :regular_writer, :[]= unless method_defined?(:regular_writer) - - def []=(key, value) - regular_writer(key.is_a?(String) ? key.to_sym : key, value) - end -end - -module ActiveSupport #:nodoc: - module CoreExtensions #:nodoc: - module Hash #:nodoc: - module IndifferentAccess - def with_indifferent_access - HashWithIndifferentAccess.new(self) - end - end - end - end -end diff --git a/activesupport/lib/core_ext/hash/keys.rb b/activesupport/lib/core_ext/hash/keys.rb deleted file mode 100644 index 8725138856..0000000000 --- a/activesupport/lib/core_ext/hash/keys.rb +++ /dev/null @@ -1,53 +0,0 @@ -module ActiveSupport #:nodoc: - module CoreExtensions #:nodoc: - module Hash #:nodoc: - module Keys - # Return a new hash with all keys converted to strings. - def stringify_keys - inject({}) do |options, (key, value)| - options[key.to_s] = value - options - end - end - - # Destructively convert all keys to strings. - def stringify_keys! - keys.each do |key| - unless key.class.to_s == "String" # weird hack to make the tests run when string_ext_test.rb is also running - self[key.to_s] = self[key] - delete(key) - end - end - self - end - - # Return a new hash with all keys converted to symbols. - def symbolize_keys - inject({}) do |options, (key, value)| - options[key.to_sym] = value - options - end - end - - # Destructively convert all keys to symbols. - def symbolize_keys! - keys.each do |key| - unless key.is_a?(Symbol) - self[key.to_sym] = self[key] - delete(key) - end - end - self - end - - alias_method :to_options, :symbolize_keys - alias_method :to_options!, :symbolize_keys! - - def assert_valid_keys(valid_keys) - unknown_keys = keys - valid_keys - raise(ArgumentError, "Unknown key(s): #{unknown_keys.join(", ")}") unless unknown_keys.empty? - end - end - end - end -end diff --git a/activesupport/lib/core_ext/numeric.rb b/activesupport/lib/core_ext/numeric.rb deleted file mode 100644 index 88fead7aa4..0000000000 --- a/activesupport/lib/core_ext/numeric.rb +++ /dev/null @@ -1,7 +0,0 @@ -require File.dirname(__FILE__) + '/numeric/time' -require File.dirname(__FILE__) + '/numeric/bytes' - -class Numeric #:nodoc: - include ActiveSupport::CoreExtensions::Numeric::Time - include ActiveSupport::CoreExtensions::Numeric::Bytes -end diff --git a/activesupport/lib/core_ext/numeric/bytes.rb b/activesupport/lib/core_ext/numeric/bytes.rb deleted file mode 100644 index 98e5e13abb..0000000000 --- a/activesupport/lib/core_ext/numeric/bytes.rb +++ /dev/null @@ -1,33 +0,0 @@ -module ActiveSupport #:nodoc: - module CoreExtensions #:nodoc: - module Numeric #:nodoc: - # Enables the use of byte calculations and declarations, like 45.bytes + 2.6.megabytes - module Bytes - def bytes - self - end - alias :byte :bytes - - def kilobytes - self * 1024 - end - alias :kilobyte :kilobytes - - def megabytes - self * 1024.kilobytes - end - alias :megabyte :megabytes - - def gigabytes - self * 1024.megabytes - end - alias :gigabyte :gigabytes - - def terabytes - self * 1024.gigabytes - end - alias :terabyte :terabytes - end - end - end -end diff --git a/activesupport/lib/core_ext/numeric/time.rb b/activesupport/lib/core_ext/numeric/time.rb deleted file mode 100644 index 43c0425b00..0000000000 --- a/activesupport/lib/core_ext/numeric/time.rb +++ /dev/null @@ -1,59 +0,0 @@ -module ActiveSupport #:nodoc: - module CoreExtensions #:nodoc: - module Numeric #:nodoc: - # Enables the use of time calculations and declarations, like 45.minutes + 2.hours + 4.years - module Time - def minutes - self * 60 - end - alias :minute :minutes - - def hours - self * 60.minutes - end - alias :hour :hours - - def days - self * 24.hours - end - alias :day :days - - def weeks - self * 7.days - end - alias :week :weeks - - def fortnights - self * 2.weeks - end - alias :fortnight :fortnights - - def months - self * 30.days - end - alias :month :months - - def years - self * 365.days - end - alias :year :years - - # Reads best without arguments: 10.minutes.ago - def ago(time = ::Time.now) - time - self - end - - # Reads best with argument: 10.minutes.until(time) - alias :until :ago - - # Reads best with argument: 10.minutes.since(time) - def since(time = ::Time.now) - time + self - end - - # Reads best without arguments: 10.minutes.from_now - alias :from_now :since - end - end - end -end diff --git a/activesupport/lib/core_ext/object_and_class.rb b/activesupport/lib/core_ext/object_and_class.rb deleted file mode 100644 index 59a463ae29..0000000000 --- a/activesupport/lib/core_ext/object_and_class.rb +++ /dev/null @@ -1,24 +0,0 @@ -class Object #:nodoc: - def remove_subclasses_of(superclass) - subclasses_of(superclass).each { |subclass| Object.send(:remove_const, subclass) rescue nil } - end - - def subclasses_of(superclass) - subclasses = [] - ObjectSpace.each_object(Class) do |k| - next if !k.ancestors.include?(superclass) || superclass == k || k.to_s.include?("::") || subclasses.include?(k.to_s) - subclasses << k.to_s - end - subclasses - end -end - -class Class #:nodoc: - def remove_subclasses - Object.remove_subclasses_of(self) - end - - def subclasses - Object.subclasses_of(self) - end -end diff --git a/activesupport/lib/core_ext/string.rb b/activesupport/lib/core_ext/string.rb deleted file mode 100644 index 6d554b483c..0000000000 --- a/activesupport/lib/core_ext/string.rb +++ /dev/null @@ -1,5 +0,0 @@ -require File.dirname(__FILE__) + '/string/inflections' - -class String #:nodoc: - include ActiveSupport::CoreExtensions::String::Inflections -end diff --git a/activesupport/lib/core_ext/string/inflections.rb b/activesupport/lib/core_ext/string/inflections.rb deleted file mode 100644 index aa4ff3a74d..0000000000 --- a/activesupport/lib/core_ext/string/inflections.rb +++ /dev/null @@ -1,49 +0,0 @@ -require File.dirname(__FILE__) + '/../../inflector' -module ActiveSupport #:nodoc: - module CoreExtensions #:nodoc: - module String #:nodoc: - # Makes it possible to do "posts".singularize that returns "post" and "MegaCoolClass".underscore that returns "mega_cool_class". - module Inflections - def pluralize - Inflector.pluralize(self) - end - - def singularize - Inflector.singularize(self) - end - - def camelize - Inflector.camelize(self) - end - - def underscore - Inflector.underscore(self) - end - - def demodulize - Inflector.demodulize(self) - end - - def tableize - Inflector.tableize(self) - end - - def classify - Inflector.classify(self) - end - - def humanize - Inflector.humanize(self) - end - - def foreign_key(separate_class_name_and_id_with_underscore = true) - Inflector.foreign_key(self, separate_class_name_and_id_with_underscore) - end - - def constantize - Inflector.constantize(self) - end - end - end - end -end |