Permalink
Browse files

Merge pull request #15 from KL-7/resource-for

Add TwitterCldr.get_resource that delegates to Resources#resource_for to make things a little less verbose :)
  • Loading branch information...
2 parents 9ca8032 + 9a26710 commit e562b6e1e7be1777e03e8d55e0fbf47b39d1f8db @camertron camertron committed Apr 12, 2012
@@ -27,7 +27,7 @@ def rule_for(number, locale = TwitterCldr::get_locale)
def get_resource(locale)
locale = TwitterCldr.convert_locale(locale)
- eval(TwitterCldr.resources.resource_for(locale, "plurals")[locale])
+ eval(TwitterCldr.get_resource(locale, "plurals")[locale])
end
end
end
View
@@ -3,7 +3,7 @@
module TwitterCldr
module Shared
class Currencies
- @@resource = TwitterCldr.resources.resource_for("shared", "currencies")[:shared][:currencies]
+ @@resource = TwitterCldr.get_resource("shared", "currencies")[:shared][:currencies]
class << self
def countries
View
@@ -42,7 +42,7 @@ def translate_language(language, source_locale = :en, dest_locale = TwitterCldr:
def get_resource(locale)
locale = TwitterCldr.convert_locale(locale)
- TwitterCldr.resources.resource_for(locale, "languages")[locale]
+ TwitterCldr.get_resource(locale, "languages")[locale]
end
end
end
@@ -32,7 +32,7 @@ def calendar
protected
def init_resources
- @resource = TwitterCldr.resources.resource_for(@locale, "calendars")[TwitterCldr.convert_locale(@locale)]
+ @resource = TwitterCldr.get_resource(@locale, "calendars")[TwitterCldr.convert_locale(@locale)]
end
def init_placeholders
@@ -40,7 +40,7 @@ def full_path_for(path)
end
def init_resources
- @resource = TwitterCldr.resources.resource_for(@locale, "numbers")[TwitterCldr.convert_locale(@locale)]
+ @resource = TwitterCldr.get_resource(@locale, "numbers")[TwitterCldr.convert_locale(@locale)]
end
def pattern_for(resource)
View
@@ -7,6 +7,7 @@
require 'yaml'
require 'date'
require 'time'
+require 'forwardable'
require 'version'
@@ -26,6 +27,9 @@
module TwitterCldr
+
+ extend SingleForwardable
+
DEFAULT_LOCALE = :en
RESOURCE_DIR = File.join(File.dirname(File.dirname(File.expand_path(__FILE__))), "resources")
@@ -36,6 +40,8 @@ module TwitterCldr
@@resources = TwitterCldr::Shared::Resources.new
+ def_delegator :resources, :resource_for, :get_resource
+
def self.get_resource_file(locale, resource)
File.join(RESOURCE_DIR, self.convert_locale(locale).to_s, "#{resource}.yml")
end
@@ -75,6 +81,7 @@ def self.supported_locale?(locale)
locale = locale.to_sym
self.supported_locales.include?(locale) || self.supported_locales.include?(self.convert_locale(locale))
end
+
end
View
@@ -52,4 +52,23 @@
end
end
end
+
+ describe '#resources' do
+ it 'returns @@resources' do
+ resources = TwitterCldr::Shared::Resources.new
+ TwitterCldr.send :class_variable_set, :@@resources, resources
+
+ TwitterCldr.resources.should == resources
+ end
+ end
+
+ describe '#get_resource' do
+ it 'delegates to @@resources' do
+ resources = TwitterCldr::Shared::Resources.new
+ mock(resources).resource_for('locale', 'resource') { 'result' }
+ TwitterCldr.send :class_variable_set, :@@resources, resources
+
+ TwitterCldr.get_resource('locale', 'resource').should == 'result'
+ end
+ end
end

0 comments on commit e562b6e

Please sign in to comment.