aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support
diff options
context:
space:
mode:
Diffstat (limited to 'activesupport/lib/active_support')
-rw-r--r--activesupport/lib/active_support/cache/strategy/local_cache.rb2
-rw-r--r--activesupport/lib/active_support/core_ext/try.rb13
-rw-r--r--activesupport/lib/active_support/ordered_hash.rb4
-rwxr-xr-xactivesupport/lib/active_support/vendor/i18n-0.1.1/lib/i18n.rb5
-rw-r--r--activesupport/lib/active_support/vendor/i18n-0.1.1/lib/i18n/backend/simple.rb8
-rw-r--r--activesupport/lib/active_support/vendor/i18n-0.1.1/test/simple_backend_test.rb22
6 files changed, 48 insertions, 6 deletions
diff --git a/activesupport/lib/active_support/cache/strategy/local_cache.rb b/activesupport/lib/active_support/cache/strategy/local_cache.rb
index 621358d701..d83e259a2a 100644
--- a/activesupport/lib/active_support/cache/strategy/local_cache.rb
+++ b/activesupport/lib/active_support/cache/strategy/local_cache.rb
@@ -41,7 +41,7 @@ module ActiveSupport
value
else
# forcing the value to be immutable
- value.dup
+ value.duplicable? ? value.dup : value
end
end
diff --git a/activesupport/lib/active_support/core_ext/try.rb b/activesupport/lib/active_support/core_ext/try.rb
index 0dccd40c55..54a38c5189 100644
--- a/activesupport/lib/active_support/core_ext/try.rb
+++ b/activesupport/lib/active_support/core_ext/try.rb
@@ -1,6 +1,9 @@
class Object
- # Tries to send the method only if object responds to it. Return +nil+ otherwise.
- # It will also forward any arguments and/or block like Object#send does.
+ # Invokes the method identified by the symbol +method+, passing it any arguments
+ # and/or the block specified, just like the regular Ruby <tt>Object#send</tt> does.
+ #
+ # *Unlike* that method however, a +NoMethodError+ exception will *not* be raised
+ # and +nil+ will be returned instead, if the receiving object is a +nil+ object or NilClass.
#
# ==== Examples
#
@@ -12,11 +15,13 @@ class Object
# With try
# @person.try(:name)
#
- # Try also accepts arguments/blocks for the method it is trying
+ # +try+ also accepts arguments and/or a block, for the method it is trying
# Person.try(:find, 1)
# @people.try(:collect) {|p| p.name}
#--
- # This method def is for rdoc only. The alias_method below overrides it as an optimization.
+ # This method definition below is for rdoc purposes only. The alias_method call
+ # below overrides it as an optimization since +try+ behaves like +Object#send+,
+ # unless called on +NilClass+.
def try(method, *args, &block)
send(method, *args, &block)
end
diff --git a/activesupport/lib/active_support/ordered_hash.rb b/activesupport/lib/active_support/ordered_hash.rb
index 25ea505813..66aab9e562 100644
--- a/activesupport/lib/active_support/ordered_hash.rb
+++ b/activesupport/lib/active_support/ordered_hash.rb
@@ -92,6 +92,10 @@ module ActiveSupport
dup.merge!(other_hash)
end
+ def inspect
+ "#<OrderedHash #{self.to_hash.inspect}>"
+ end
+
private
def sync_keys!
diff --git a/activesupport/lib/active_support/vendor/i18n-0.1.1/lib/i18n.rb b/activesupport/lib/active_support/vendor/i18n-0.1.1/lib/i18n.rb
index b5ad094d0e..76361bed90 100755
--- a/activesupport/lib/active_support/vendor/i18n-0.1.1/lib/i18n.rb
+++ b/activesupport/lib/active_support/vendor/i18n-0.1.1/lib/i18n.rb
@@ -45,6 +45,11 @@ module I18n
Thread.current[:locale] = locale
end
+ # Returns an array of locales for which translations are available
+ def available_locales
+ backend.available_locales
+ end
+
# Sets the exception handler.
def exception_handler=(exception_handler)
@@exception_handler = exception_handler
diff --git a/activesupport/lib/active_support/vendor/i18n-0.1.1/lib/i18n/backend/simple.rb b/activesupport/lib/active_support/vendor/i18n-0.1.1/lib/i18n/backend/simple.rb
index d298b3a85a..b54164d496 100644
--- a/activesupport/lib/active_support/vendor/i18n-0.1.1/lib/i18n/backend/simple.rb
+++ b/activesupport/lib/active_support/vendor/i18n-0.1.1/lib/i18n/backend/simple.rb
@@ -69,6 +69,12 @@ module I18n
@initialized ||= false
end
+ # Returns an array of locales for which translations are available
+ def available_locales
+ init_translations unless initialized?
+ translations.keys
+ end
+
def reload!
@initialized = false
@translations = nil
@@ -76,7 +82,7 @@ module I18n
protected
def init_translations
- load_translations(*I18n.load_path)
+ load_translations(*I18n.load_path.flatten)
@initialized = true
end
diff --git a/activesupport/lib/active_support/vendor/i18n-0.1.1/test/simple_backend_test.rb b/activesupport/lib/active_support/vendor/i18n-0.1.1/test/simple_backend_test.rb
index e181975f38..8ba7036abf 100644
--- a/activesupport/lib/active_support/vendor/i18n-0.1.1/test/simple_backend_test.rb
+++ b/activesupport/lib/active_support/vendor/i18n-0.1.1/test/simple_backend_test.rb
@@ -124,6 +124,16 @@ class I18nSimpleBackendTranslationsTest < Test::Unit::TestCase
end
end
+class I18nSimpleBackendAvailableLocalesTest < Test::Unit::TestCase
+ def test_available_locales
+ @backend = I18n::Backend::Simple.new
+ @backend.store_translations 'de', :foo => 'bar'
+ @backend.store_translations 'en', :foo => 'foo'
+
+ assert_equal ['de', 'en'], @backend.available_locales.map{|locale| locale.to_s }.sort
+ end
+end
+
class I18nSimpleBackendTranslateTest < Test::Unit::TestCase
include I18nSimpleBackendTestSetup
@@ -472,6 +482,18 @@ class I18nSimpleBackendLoadTranslationsTest < Test::Unit::TestCase
end
end
+class I18nSimpleBackendLoadPathTest < Test::Unit::TestCase
+ include I18nSimpleBackendTestSetup
+
+ def test_nested_load_paths_do_not_break_locale_loading
+ @backend = I18n::Backend::Simple.new
+ I18n.load_path = [[File.dirname(__FILE__) + '/locale/en.yml']]
+ assert_nil backend_get_translations
+ assert_nothing_raised { @backend.send :init_translations }
+ assert_not_nil backend_get_translations
+ end
+end
+
class I18nSimpleBackendReloadTranslationsTest < Test::Unit::TestCase
include I18nSimpleBackendTestSetup