Class: TwitterCldr::Resources::Loader

Inherits:
Object
  • Object
show all
Defined in:
lib/twitter_cldr/resources/loader.rb

Instance Method Summary collapse

Instance Method Details

#absolute_resource_path(path) ⇒ Object



21
22
23
# File 'lib/twitter_cldr/resources/loader.rb', line 21

def absolute_resource_path(path)
  File.join(TwitterCldr::RESOURCES_DIR, path)
end

#get_locale_resource(locale, resource_name) ⇒ Object



25
26
27
# File 'lib/twitter_cldr/resources/loader.rb', line 25

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_loaded?(locale, resource_name) ⇒ Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/twitter_cldr/resources/loader.rb', line 33

def locale_resource_loaded?(locale, resource_name)
  resource_loaded?(*locale_resource_path(locale, resource_name))
end

#preload_all_resourcesObject



65
66
67
68
69
70
# File 'lib/twitter_cldr/resources/loader.rb', line 65

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



51
52
53
54
55
56
# File 'lib/twitter_cldr/resources/loader.rb', line 51

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



58
59
60
61
62
63
# File 'lib/twitter_cldr/resources/loader.rb', line 58

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



43
44
45
46
47
48
49
# File 'lib/twitter_cldr/resources/loader.rb', line 43

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

Returns:

  • (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_loaded?(*path) ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/twitter_cldr/resources/loader.rb', line 29

def resource_loaded?(*path)
  resources_cache.include?(resource_file_path(path))
end

#resource_types_for(locale) ⇒ Object



37
38
39
40
41
# File 'lib/twitter_cldr/resources/loader.rb', line 37

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