Class: Zmeygo::Cache
- Inherits:
-
Object
- Object
- Zmeygo::Cache
- Defined in:
- lib/zmeygo/cache.rb
Overview
Cache is responsable to gather missing keys from I18n.t/I18n.translate calls and once in a while send them to server. Server where keys will be sent is configured in config file Zmeygo.config All keys sent are for project mentioned in Zmeygo.config
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
-
#missing_keys ⇒ Object
Returns the value of attribute missing_keys.
Instance Method Summary collapse
- #add_to_cache(key) ⇒ Object
- #clear_cache ⇒ Object
- #get_cache ⇒ Object
- #get_cache_proj ⇒ Object
-
#initialize ⇒ Cache
constructor
A new instance of Cache.
- #validate_config! ⇒ Object
Constructor Details
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
9 10 11 |
# File 'lib/zmeygo/cache.rb', line 9 def config @config end |
#missing_keys ⇒ Object
Returns the value of attribute missing_keys.
10 11 12 |
# File 'lib/zmeygo/cache.rb', line 10 def missing_keys @missing_keys end |
Instance Method Details
#add_to_cache(key) ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/zmeygo/cache.rb', line 27 def add_to_cache(key) proj = validate_config! self.missing_keys[proj] ||= {} self.missing_keys[proj][key] = true File.open(File.(Constant::CACHE_FILE),'w') do |f| f.write(Marshal.dump(self.missing_keys)) end end |
#clear_cache ⇒ Object
36 37 38 39 40 |
# File 'lib/zmeygo/cache.rb', line 36 def clear_cache proj = validate_config! self.missing_keys[proj].clear File.truncate(File.(Constant::CACHE_FILE),0) end |
#get_cache ⇒ Object
22 23 24 25 |
# File 'lib/zmeygo/cache.rb', line 22 def get_cache proj = validate_config! self.missing_keys[proj] end |
#get_cache_proj ⇒ Object
17 18 19 20 |
# File 'lib/zmeygo/cache.rb', line 17 def get_cache_proj proj = validate_config! proj end |
#validate_config! ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/zmeygo/cache.rb', line 42 def validate_config! proj = self.config['default_project'] if proj.blank? raise "Please provide default project name in ~/.zmeygo/config.yml file" end self.missing_keys[proj] ||= {} proj end |