Class: TwitterCldr::Resources::Loader
- Inherits:
-
Object
- Object
- TwitterCldr::Resources::Loader
- Defined in:
- lib/twitter_cldr/resources/loader.rb
Instance Method Summary collapse
- #absolute_resource_path(path) ⇒ Object
- #get_locale_resource(locale, resource_name) ⇒ Object
- #get_resource(*path) ⇒ Object
- #locale_resource_exists?(locale, resource_name) ⇒ Boolean
- #locale_resource_loaded?(locale, resource_name) ⇒ Boolean
- #preload_all_resources ⇒ Object
- #preload_resource_for_locales(resource, *locales) ⇒ Object
- #preload_resources_for_all_locales(*resources) ⇒ Object
- #preload_resources_for_locale(locale, *resources) ⇒ Object
- #resource_exists?(*path) ⇒ Boolean
- #resource_file_path(path) ⇒ Object
- #resource_loaded?(*path) ⇒ Boolean
- #resource_types_for(locale) ⇒ Object
Instance Method Details
#absolute_resource_path(path) ⇒ Object
25 26 27 |
# File 'lib/twitter_cldr/resources/loader.rb', line 25 def absolute_resource_path(path) File.join(TwitterCldr::RESOURCES_DIR, path) end |
#get_locale_resource(locale, resource_name) ⇒ Object
29 30 31 |
# File 'lib/twitter_cldr/resources/loader.rb', line 29 def get_locale_resource(locale, resource_name) get_resource(*locale_resource_path(locale, resource_name)) end |
#get_resource(*path) ⇒ Object
13 14 15 |
# File 'lib/twitter_cldr/resources/loader.rb', line 13 def get_resource(*path) resources_cache[resource_file_path(path)] end |
#locale_resource_exists?(locale, resource_name) ⇒ Boolean
21 22 23 |
# File 'lib/twitter_cldr/resources/loader.rb', line 21 def locale_resource_exists?(locale, resource_name) resource_exists?(*locale_resource_path(locale, resource_name)) end |
#locale_resource_loaded?(locale, resource_name) ⇒ Boolean
37 38 39 |
# File 'lib/twitter_cldr/resources/loader.rb', line 37 def locale_resource_loaded?(locale, resource_name) resource_loaded?(*locale_resource_path(locale, resource_name)) end |
#preload_all_resources ⇒ Object
69 70 71 72 73 74 |
# File 'lib/twitter_cldr/resources/loader.rb', line 69 def preload_all_resources TwitterCldr.supported_locales.each do |locale| preload_resources_for_locale(locale, :all) end nil end |
#preload_resource_for_locales(resource, *locales) ⇒ Object
55 56 57 58 59 60 |
# File 'lib/twitter_cldr/resources/loader.rb', line 55 def preload_resource_for_locales(resource, *locales) locales.each do |locale| preload_resources_for_locale(locale, resource) end nil end |
#preload_resources_for_all_locales(*resources) ⇒ Object
62 63 64 65 66 67 |
# File 'lib/twitter_cldr/resources/loader.rb', line 62 def preload_resources_for_all_locales(*resources) TwitterCldr.supported_locales.each do |locale| preload_resources_for_locale(locale, *resources) end nil end |
#preload_resources_for_locale(locale, *resources) ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/twitter_cldr/resources/loader.rb', line 47 def preload_resources_for_locale(locale, *resources) if resources.size > 0 resources = resource_types_for(locale) if resources.first == :all resources.each { |res| get_locale_resource(locale, res) } end nil end |
#resource_exists?(*path) ⇒ Boolean
17 18 19 |
# File 'lib/twitter_cldr/resources/loader.rb', line 17 def resource_exists?(*path) File.exist?(absolute_resource_path(resource_file_path(path))) end |
#resource_file_path(path) ⇒ Object
76 77 78 79 80 |
# File 'lib/twitter_cldr/resources/loader.rb', line 76 def resource_file_path(path) file = File.join(*path.map(&:to_s)) file << '.yml' unless file.end_with?('.yml') file end |
#resource_loaded?(*path) ⇒ Boolean
33 34 35 |
# File 'lib/twitter_cldr/resources/loader.rb', line 33 def resource_loaded?(*path) resources_cache.include?(resource_file_path(path)) end |
#resource_types_for(locale) ⇒ Object
41 42 43 44 45 |
# File 'lib/twitter_cldr/resources/loader.rb', line 41 def resource_types_for(locale) Dir.glob(File.join(RESOURCES_DIR, 'locales', locale.to_s, '*')).map do |file| File.basename(file).chomp(File.extname(file)).to_sym end end |