Permalink
Browse files

Rename Shared::Resources into Resoures::Loader.

  • Loading branch information...
1 parent bf8aeb5 commit 59efe395513537c9684c620b15428aa4eac8dab8 @KL-7 KL-7 committed Jul 10, 2012
View
@@ -23,6 +23,7 @@ module TwitterCldr
autoload :Formatters, 'twitter_cldr/formatters'
autoload :Collation, 'twitter_cldr/collation'
autoload :Normalization, 'twitter_cldr/normalization'
+ autoload :Resources, 'twitter_cldr/resources'
autoload :Shared, 'twitter_cldr/shared'
autoload :Tokenizers, 'twitter_cldr/tokenizers'
autoload :Utils, 'twitter_cldr/utils'
@@ -54,7 +55,7 @@ module TwitterCldr
class << self
def resources
- @resources ||= TwitterCldr::Shared::Resources.new
+ @resources ||= TwitterCldr::Resources::Loader.new
end
def get_locale
@@ -0,0 +1,10 @@
+# encoding: UTF-8
+
+# Copyright 2012 Twitter, Inc
+# http://www.apache.org/licenses/LICENSE-2.0
+
+module TwitterCldr
+ module Resources
+ autoload :Loader, 'twitter_cldr/resources/loader'
+ end
+end
@@ -4,8 +4,9 @@
# http://www.apache.org/licenses/LICENSE-2.0
module TwitterCldr
- module Shared
- class Resources
+ module Resources
+
+ class Loader
def get_resource(*path)
resources_cache[resource_file_path(path)]
@@ -40,5 +41,6 @@ def read_resource_file(path)
end
end
+
end
end
@@ -9,7 +9,6 @@ module Shared
autoload :Currencies, 'twitter_cldr/shared/currencies'
autoload :Languages, 'twitter_cldr/shared/languages'
autoload :Numbers, 'twitter_cldr/shared/numbers'
- autoload :Resources, 'twitter_cldr/shared/resources'
autoload :CodePoint, 'twitter_cldr/shared/code_point'
end
end
@@ -5,64 +5,64 @@
require 'spec_helper'
-include TwitterCldr::Shared
+include TwitterCldr::Resources
-describe Resources do
- let(:resources) { Resources.new }
+describe Loader do
+ let(:loader) { Loader.new }
describe '#get_resource' do
let(:resource_path) { 'random/resource.yml' }
let(:resource_content) { 'random YAML content' }
it 'loads the correct YAML file' do
stub_resource_file(resource_path, "---\n- 1\n- 2\n")
- resources.get_resource(:random, :resource).should == [1, 2]
+ loader.get_resource(:random, :resource).should == [1, 2]
end
it 'symbolizes hash keys' do
stub_resource_file(resource_path, "---\na:\n b: 3\n")
- resources.get_resource(:random, :resource).should == { :a => { :b => 3 } }
+ loader.get_resource(:random, :resource).should == { :a => { :b => 3 } }
end
it 'loads the resource only once' do
- mock(resources).load_resource(resource_path).once { resource_content }
+ mock(loader).load_resource(resource_path).once { resource_content }
- result = resources.get_resource(:random, :resource)
+ result = loader.get_resource(:random, :resource)
result.should == resource_content
# second time load_resource is not called but we get the same object as before
- resources.get_resource(:random, :resource).object_id.should == result.object_id
+ loader.get_resource(:random, :resource).object_id.should == result.object_id
end
it 'accepts a variable length resource path both in symbols and strings' do
- stub(resources).load_resource('foo/bar/baz.yml') { 'foo-bar-baz' }
- resources.get_resource('foo', :bar, 'baz').should == 'foo-bar-baz'
+ stub(loader).load_resource('foo/bar/baz.yml') { 'foo-bar-baz' }
+ loader.get_resource('foo', :bar, 'baz').should == 'foo-bar-baz'
end
it 'raises an exception if resource file is missing' do
mock(File).file?(File.join(TwitterCldr::RESOURCES_DIR, 'foo/bar.yml')) { false }
- lambda { resources.get_resource(:foo, :bar) }.should raise_error(ArgumentError, "Resource 'foo/bar.yml' not found.")
+ lambda { loader.get_resource(:foo, :bar) }.should raise_error(ArgumentError, "Resource 'foo/bar.yml' not found.")
end
end
describe '#get_locale_resource' do
it 'loads the correct locale resource file' do
- stub(resources).get_resource(:locales, :de, :numbers) { 'foo' }
- resources.get_locale_resource(:de, :numbers).should == 'foo'
+ stub(loader).get_resource(:locales, :de, :numbers) { 'foo' }
+ loader.get_locale_resource(:de, :numbers).should == 'foo'
end
it 'loads the resource only once' do
- mock(resources).load_resource('locales/de/numbers.yml').once { 'foo' }
+ mock(loader).load_resource('locales/de/numbers.yml').once { 'foo' }
- result = resources.get_locale_resource(:de, :numbers)
+ result = loader.get_locale_resource(:de, :numbers)
# second time get_resource is not called but we get the same object as before
- resources.get_locale_resource(:de, :numbers).object_id.should == result.object_id
+ loader.get_locale_resource(:de, :numbers).object_id.should == result.object_id
end
it 'converts locales' do
mock(TwitterCldr).convert_locale('zh-tw') { :'zh-Hant' }
- mock(resources).get_resource(:locales, :'zh-Hant', :numbers) { 'foo' }
+ mock(loader).get_resource(:locales, :'zh-Hant', :numbers) { 'foo' }
- resources.get_locale_resource('zh-tw', :numbers).should == 'foo'
+ loader.get_locale_resource('zh-tw', :numbers).should == 'foo'
end
end
@@ -78,14 +78,14 @@
describe '#resources' do
it 'returns @resources' do
- resources = TwitterCldr::Shared::Resources.new
- TwitterCldr.send :instance_variable_set, :@resources, resources
+ resources = TwitterCldr::Resources::Loader.new
+ TwitterCldr.instance_variable_set(:@resources, resources)
TwitterCldr.resources.should == resources
end
end
- let(:resources) { TwitterCldr::Shared::Resources.new }
+ let(:resources) { TwitterCldr::Resources::Loader.new }
describe '#get_resource' do
it 'delegates to resources' do

0 comments on commit 59efe39

Please sign in to comment.