Class: Untranslated::Spy
- Inherits:
-
I18n::ExceptionHandler
- Object
- I18n::ExceptionHandler
- Untranslated::Spy
- Defined in:
- lib/untranslated/spy.rb
Instance Method Summary collapse
- #cached_store(key) ⇒ Object
- #call(exception, locale, key, options) ⇒ Object
- #ensure_log_dir_exist ⇒ Object
- #keys ⇒ Object
- #pack(key) ⇒ Object
- #push(locale, key) ⇒ Object
- #store ⇒ Object
Instance Method Details
#cached_store(key) ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/untranslated/spy.rb', line 31 def cached_store key @cache ||= {} store unless @cache[key] @cache[key] ||= true end |
#call(exception, locale, key, options) ⇒ Object
5 6 7 8 9 |
# File 'lib/untranslated/spy.rb', line 5 def call(exception, locale, key, ) push locale, key super(exception, locale, key, ) end |
#ensure_log_dir_exist ⇒ Object
51 52 53 54 55 |
# File 'lib/untranslated/spy.rb', line 51 def ensure_log_dir_exist return if Dir.exist? './log' Dir.mkdir './log' end |
#keys ⇒ Object
57 58 59 |
# File 'lib/untranslated/spy.rb', line 57 def keys @keys ||= {} end |
#pack(key) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/untranslated/spy.rb', line 19 def pack key path = key.split ::I18n.default_separator reverse_path = path.reverse reverse_path.inject('') do |hash, k| out = {} out[k] = hash out end end |
#push(locale, key) ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/untranslated/spy.rb', line 11 def push locale, key path = [locale, key].join ::I18n.default_separator packed = pack path keys.deep_merge! packed cached_store key end |
#store ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/untranslated/spy.rb', line 39 def store ensure_log_dir_exist keys.each do |locale, key| ::File.open("./log/untranslated.#{locale}.yml", 'w') do |f| prefixed = {} prefixed[locale] = key f.write(prefixed.to_yaml) end end end |