diff options
author | wycats <wycats@gmail.com> | 2010-03-26 15:10:24 -0700 |
---|---|---|
committer | wycats <wycats@gmail.com> | 2010-03-26 15:10:24 -0700 |
commit | 197904341f2b2f21d69c653cede3aec124e86720 (patch) | |
tree | 83f1234e238016126860a929594db22e1862d783 /activesupport/lib | |
parent | 76d2c455c0607b4cd5f238cadef8f933a18567fb (diff) | |
parent | b3a0aed028835ce4551c4a76742744a40a71b0be (diff) | |
download | rails-197904341f2b2f21d69c653cede3aec124e86720.tar.gz rails-197904341f2b2f21d69c653cede3aec124e86720.tar.bz2 rails-197904341f2b2f21d69c653cede3aec124e86720.zip |
Merge branch 'master' into docrails
Diffstat (limited to 'activesupport/lib')
20 files changed, 69 insertions, 23 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 diff --git a/activesupport/lib/active_support/inflector/transliterate.rb b/activesupport/lib/active_support/inflector/transliterate.rb index 236f2eb628..2ce27cf406 100644 --- a/activesupport/lib/active_support/inflector/transliterate.rb +++ b/activesupport/lib/active_support/inflector/transliterate.rb @@ -14,8 +14,8 @@ module ActiveSupport if RUBY_VERSION >= '1.9' undef_method :transliterate def transliterate(string) - warn "Ruby 1.9 doesn't support Unicode normalization yet" - string.dup + proxy = ActiveSupport::Multibyte.proxy_class.new(string) + proxy.normalize(:kd).gsub(/[^\x00-\x7F]+/, '') end # The iconv transliteration code doesn't function correctly diff --git a/activesupport/lib/active_support/multibyte.rb b/activesupport/lib/active_support/multibyte.rb index 7e6f7d754b..428c48a484 100644 --- a/activesupport/lib/active_support/multibyte.rb +++ b/activesupport/lib/active_support/multibyte.rb @@ -53,8 +53,8 @@ module ActiveSupport #:nodoc: \xf4 [\x80-\x8f] [\x80-\xbf] [\x80-\xbf])\z /xn, # Quick check for valid Shift-JIS characters, disregards the odd-even pairing 'Shift_JIS' => /\A(?: - [\x00-\x7e \xa1-\xdf] | - [\x81-\x9f \xe0-\xef] [\x40-\x7e \x80-\x9e \x9f-\xfc])\z /xn + [\x00-\x7e\xa1-\xdf] | + [\x81-\x9f\xe0-\xef] [\x40-\x7e\x80-\x9e\x9f-\xfc])\z /xn } end end diff --git a/activesupport/lib/active_support/multibyte/utils.rb b/activesupport/lib/active_support/multibyte/utils.rb index b243df46d8..94b393cee2 100644 --- a/activesupport/lib/active_support/multibyte/utils.rb +++ b/activesupport/lib/active_support/multibyte/utils.rb @@ -27,7 +27,7 @@ module ActiveSupport #:nodoc: def self.verify(string) if expression = valid_character # Splits the string on character boundaries, which are determined based on $KCODE. - string.split(//).all? { |c| expression.match(c) } + string.split(//).all? { |c| expression =~ c } else true end diff --git a/activesupport/lib/active_support/notifications/fanout.rb b/activesupport/lib/active_support/notifications/fanout.rb index cd60054862..a3ddc7705a 100644 --- a/activesupport/lib/active_support/notifications/fanout.rb +++ b/activesupport/lib/active_support/notifications/fanout.rb @@ -44,7 +44,7 @@ module ActiveSupport when Regexp, NilClass pattern else - /^#{Regexp.escape(pattern.to_s)}/ + /^#{Regexp.escape(pattern.to_s)}$/ end end diff --git a/activesupport/lib/active_support/railtie.rb b/activesupport/lib/active_support/railtie.rb index d2c13e030d..e45d16ee96 100644 --- a/activesupport/lib/active_support/railtie.rb +++ b/activesupport/lib/active_support/railtie.rb @@ -3,7 +3,7 @@ require "rails" module ActiveSupport class Railtie < Rails::Railtie - railtie_name :active_support + config.active_support = ActiveSupport::OrderedOptions.new # Loads support for "whiny nil" (noisy warnings when methods are invoked # on +nil+ values) if Configuration#whiny_nils is true. @@ -30,9 +30,7 @@ end module I18n class Railtie < Rails::Railtie - railtie_name :i18n - - # Initialize I18n load paths to an array + config.i18n = ActiveSupport::OrderedOptions.new config.i18n.railties_load_path = [] config.i18n.load_path = [] diff --git a/activesupport/lib/active_support/ruby/shim.rb b/activesupport/lib/active_support/ruby/shim.rb index f0db5b3021..4a9ac920e8 100644 --- a/activesupport/lib/active_support/ruby/shim.rb +++ b/activesupport/lib/active_support/ruby/shim.rb @@ -18,3 +18,4 @@ 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' +require 'active_support/core_ext/module/method_names'
\ No newline at end of file diff --git a/activesupport/lib/active_support/test_case.rb b/activesupport/lib/active_support/test_case.rb index ab30984d62..ed8c02ba3e 100644 --- a/activesupport/lib/active_support/test_case.rb +++ b/activesupport/lib/active_support/test_case.rb @@ -5,9 +5,10 @@ require 'active_support/testing/deprecation' require 'active_support/testing/declarative' require 'active_support/testing/pending' require 'active_support/testing/isolation' +require 'active_support/core_ext/kernel/reporting' begin - require 'mocha' + silence_warnings { require 'mocha' } rescue LoadError # Fake Mocha::ExpectationError so we can rescue it in #run. Bleh. Object.const_set :Mocha, Module.new diff --git a/activesupport/lib/active_support/testing/isolation.rb b/activesupport/lib/active_support/testing/isolation.rb index 453f4fcc0f..9507dbf473 100644 --- a/activesupport/lib/active_support/testing/isolation.rb +++ b/activesupport/lib/active_support/testing/isolation.rb @@ -78,8 +78,8 @@ module ActiveSupport @@ran_class_setup = true end - serialized = run_in_isolation do |runner| - super(runner) + serialized = run_in_isolation do |isolated_runner| + super(isolated_runner) end retval, proxy = Marshal.load(serialized) diff --git a/activesupport/lib/active_support/values/time_zone.rb b/activesupport/lib/active_support/values/time_zone.rb index 4db3dd1705..3cb4d89e02 100644 --- a/activesupport/lib/active_support/values/time_zone.rb +++ b/activesupport/lib/active_support/values/time_zone.rb @@ -305,8 +305,8 @@ module ActiveSupport # TODO: Preload instead of lazy load for thread safety def tzinfo - require 'tzinfo' unless defined?(TZInfo) - @tzinfo ||= TZInfo::Timezone.get(MAPPING[name]) + require 'tzinfo' unless defined?(::TZInfo) + @tzinfo ||= ::TZInfo::Timezone.get(MAPPING[name]) end unless const_defined?(:ZONES) |