aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/core_ext
diff options
context:
space:
mode:
authorwycats <wycats@gmail.com>2010-03-26 15:10:24 -0700
committerwycats <wycats@gmail.com>2010-03-26 15:10:24 -0700
commit197904341f2b2f21d69c653cede3aec124e86720 (patch)
tree83f1234e238016126860a929594db22e1862d783 /activesupport/lib/active_support/core_ext
parent76d2c455c0607b4cd5f238cadef8f933a18567fb (diff)
parentb3a0aed028835ce4551c4a76742744a40a71b0be (diff)
downloadrails-197904341f2b2f21d69c653cede3aec124e86720.tar.gz
rails-197904341f2b2f21d69c653cede3aec124e86720.tar.bz2
rails-197904341f2b2f21d69c653cede3aec124e86720.zip
Merge branch 'master' into docrails
Diffstat (limited to 'activesupport/lib/active_support/core_ext')
-rw-r--r--activesupport/lib/active_support/core_ext/class/attribute.rb3
-rw-r--r--activesupport/lib/active_support/core_ext/class/delegating_attributes.rb5
-rw-r--r--activesupport/lib/active_support/core_ext/date_time/conversions.rb1
-rw-r--r--activesupport/lib/active_support/core_ext/hash/conversions.rb9
-rw-r--r--activesupport/lib/active_support/core_ext/module.rb4
-rw-r--r--activesupport/lib/active_support/core_ext/module/delegation.rb8
-rw-r--r--activesupport/lib/active_support/core_ext/module/method_names.rb14
-rw-r--r--activesupport/lib/active_support/core_ext/module/remove_method.rb6
-rw-r--r--activesupport/lib/active_support/core_ext/string/inflections.rb2
-rw-r--r--activesupport/lib/active_support/core_ext/string/output_safety.rb9
-rw-r--r--activesupport/lib/active_support/core_ext/time/conversions.rb1
11 files changed, 54 insertions, 8 deletions
diff --git a/activesupport/lib/active_support/core_ext/class/attribute.rb b/activesupport/lib/active_support/core_ext/class/attribute.rb
index c18905b369..9631a7d242 100644
--- a/activesupport/lib/active_support/core_ext/class/attribute.rb
+++ b/activesupport/lib/active_support/core_ext/class/attribute.rb
@@ -1,5 +1,6 @@
require 'active_support/core_ext/object/singleton_class'
require 'active_support/core_ext/module/delegation'
+require 'active_support/core_ext/module/remove_method'
class Class
# Declare a class-level attribute whose value is inheritable and
@@ -45,12 +46,14 @@ class Class
s.send(:define_method, attr) { }
s.send(:define_method, :"#{attr}?") { !!send(attr) }
s.send(:define_method, :"#{attr}=") do |value|
+ singleton_class.remove_possible_method(attr)
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.remove_possible_method(attr)
singleton_class.send(:define_method, attr) { value }
end if instance_writer
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 b5785bdcd3..12caa76c98 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,7 @@
require 'active_support/core_ext/object/blank'
require 'active_support/core_ext/array/extract_options'
require 'active_support/core_ext/object/singleton_class'
+require 'active_support/core_ext/module/remove_method'
class Class
def superclass_delegating_accessor(name, options = {})
@@ -27,7 +28,9 @@ 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)
+ singleton_class.remove_possible_method(method)
singleton_class.send(:define_method, method) { object }
+ remove_possible_method(method)
define_method(method) { object } if instance_reader
end
@@ -35,7 +38,7 @@ private
singleton_class.send(:define_method, "#{name}=") do |value|
_stash_object_in_method(value, name, options[:instance_reader] != false)
end
- self.send("#{name}=", nil)
+ send("#{name}=", nil)
end
end
diff --git a/activesupport/lib/active_support/core_ext/date_time/conversions.rb b/activesupport/lib/active_support/core_ext/date_time/conversions.rb
index 47a31839a6..a9f821b01e 100644
--- a/activesupport/lib/active_support/core_ext/date_time/conversions.rb
+++ b/activesupport/lib/active_support/core_ext/date_time/conversions.rb
@@ -1,4 +1,5 @@
require 'active_support/inflector'
+require 'active_support/core_ext/time/conversions'
class DateTime
# Ruby 1.9 has DateTime#to_time which internally relies on Time. We define our own #to_time which allows
diff --git a/activesupport/lib/active_support/core_ext/hash/conversions.rb b/activesupport/lib/active_support/core_ext/hash/conversions.rb
index 48b185d05e..c882434f78 100644
--- a/activesupport/lib/active_support/core_ext/hash/conversions.rb
+++ b/activesupport/lib/active_support/core_ext/hash/conversions.rb
@@ -54,6 +54,15 @@ class Hash
"string" => Proc.new { |string| string.to_s },
"yaml" => Proc.new { |yaml| YAML::load(yaml) rescue yaml },
"base64Binary" => Proc.new { |bin| ActiveSupport::Base64.decode64(bin) },
+ "binary" => Proc.new do |bin, entity|
+ case entity['encoding']
+ when 'base64'
+ ActiveSupport::Base64.decode64(bin)
+ # TODO: Add support for other encodings
+ else
+ bin
+ end
+ end,
"file" => Proc.new do |file, entity|
f = StringIO.new(ActiveSupport::Base64.decode64(file))
f.extend(FileLike)
diff --git a/activesupport/lib/active_support/core_ext/module.rb b/activesupport/lib/active_support/core_ext/module.rb
index bf272e9e73..f59fcd123c 100644
--- a/activesupport/lib/active_support/core_ext/module.rb
+++ b/activesupport/lib/active_support/core_ext/module.rb
@@ -7,4 +7,6 @@ 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
+require 'active_support/core_ext/module/deprecation'
+require 'active_support/core_ext/module/remove_method'
+require 'active_support/core_ext/module/method_names' \ No newline at end of file
diff --git a/activesupport/lib/active_support/core_ext/module/delegation.rb b/activesupport/lib/active_support/core_ext/module/delegation.rb
index 381181b2f4..b73f4c2b59 100644
--- a/activesupport/lib/active_support/core_ext/module/delegation.rb
+++ b/activesupport/lib/active_support/core_ext/module/delegation.rb
@@ -1,3 +1,5 @@
+require "active_support/core_ext/module/remove_method"
+
class Module
# Provides a delegate class method to easily expose contained objects' methods
# as your own. Pass one or more methods (specified as symbols or strings)
@@ -39,7 +41,7 @@ class Module
# class Foo
# CONSTANT_ARRAY = [0,1,2,3]
# @@class_array = [4,5,6,7]
- #
+ #
# def initialize
# @instance_array = [8,9,10,11]
# end
@@ -125,6 +127,10 @@ class Module
end
module_eval(<<-EOS, file, line)
+ if instance_methods(false).map(&:to_s).include?("#{prefix}#{method}")
+ remove_possible_method("#{prefix}#{method}")
+ end
+
def #{prefix}#{method}(*args, &block) # def customer_name(*args, &block)
#{to}.__send__(#{method.inspect}, *args, &block) # client.__send__(:name, *args, &block)
rescue NoMethodError # rescue NoMethodError
diff --git a/activesupport/lib/active_support/core_ext/module/method_names.rb b/activesupport/lib/active_support/core_ext/module/method_names.rb
new file mode 100644
index 0000000000..2eb40a83ab
--- /dev/null
+++ b/activesupport/lib/active_support/core_ext/module/method_names.rb
@@ -0,0 +1,14 @@
+class Module
+ if instance_methods[0].is_a?(Symbol)
+ def instance_method_names(*args)
+ instance_methods(*args).map(&:to_s)
+ end
+
+ def method_names(*args)
+ methods(*args).map(&:to_s)
+ end
+ else
+ alias_method :instance_method_names, :instance_methods
+ alias_method :method_names, :methods
+ end
+end \ No newline at end of file
diff --git a/activesupport/lib/active_support/core_ext/module/remove_method.rb b/activesupport/lib/active_support/core_ext/module/remove_method.rb
new file mode 100644
index 0000000000..2714a46b28
--- /dev/null
+++ b/activesupport/lib/active_support/core_ext/module/remove_method.rb
@@ -0,0 +1,6 @@
+class Module
+ def remove_possible_method(method)
+ remove_method(method)
+ rescue NameError
+ end
+end \ No newline at end of file
diff --git a/activesupport/lib/active_support/core_ext/string/inflections.rb b/activesupport/lib/active_support/core_ext/string/inflections.rb
index fbb7b79fc6..48b028bb64 100644
--- a/activesupport/lib/active_support/core_ext/string/inflections.rb
+++ b/activesupport/lib/active_support/core_ext/string/inflections.rb
@@ -1,5 +1,3 @@
-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.
#
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 9a7c520e75..3ee5bcaab4 100644
--- a/activesupport/lib/active_support/core_ext/string/output_safety.rb
+++ b/activesupport/lib/active_support/core_ext/string/output_safety.rb
@@ -1,4 +1,5 @@
-require "erb"
+require 'erb'
+require 'active_support/core_ext/object/singleton_class'
class ERB
module Util
@@ -23,12 +24,14 @@ class ERB
end
end
- undef :h
+ remove_method(:h)
alias h html_escape
- module_function :html_escape
module_function :h
+ singleton_class.send(:remove_method, :html_escape)
+ module_function :html_escape
+
# A utility method for escaping HTML entities in JSON strings.
# This method is also aliased as <tt>j</tt>.
#
diff --git a/activesupport/lib/active_support/core_ext/time/conversions.rb b/activesupport/lib/active_support/core_ext/time/conversions.rb
index 6d9c080442..86103ebce2 100644
--- a/activesupport/lib/active_support/core_ext/time/conversions.rb
+++ b/activesupport/lib/active_support/core_ext/time/conversions.rb
@@ -1,4 +1,5 @@
require 'active_support/inflector'
+require 'active_support/core_ext/time/publicize_conversion_methods'
require 'active_support/values/time_zone'
class Time