Class: Zmeygo::Cache

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initializeCache

Returns a new instance of Cache.



12
13
14
15
# File 'lib/zmeygo/cache.rb', line 12

def initialize
  self.config = Zmeygo.config
  self.missing_keys = {}
end

Instance Attribute Details

#configObject

Returns the value of attribute config.



9
10
11
# File 'lib/zmeygo/cache.rb', line 9

def config
  @config
end

#missing_keysObject

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.expand_path(Constant::CACHE_FILE),'w') do |f|
    f.write(Marshal.dump(self.missing_keys))
  end
end

#clear_cacheObject



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.expand_path(Constant::CACHE_FILE),0)
end

#get_cacheObject



22
23
24
25
# File 'lib/zmeygo/cache.rb', line 22

def get_cache
  proj = validate_config!
  self.missing_keys[proj]
end

#get_cache_projObject



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