Class: Scribo::I18nStore
- Inherits:
-
Object
- Object
- Scribo::I18nStore
- Defined in:
- lib/scribo/i18n_store.rb
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
- #content ⇒ Object
- #content=(content) ⇒ Object
-
#initialize ⇒ I18nStore
constructor
A new instance of I18nStore.
- #keys ⇒ Object
- #with(content) ⇒ Object
Constructor Details
#initialize ⇒ I18nStore
Returns a new instance of I18nStore.
25 |
# File 'lib/scribo/i18n_store.rb', line 25 def initialize; end |
Instance Method Details
#[](key) ⇒ Object
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/scribo/i18n_store.rb', line 37 def [](key) return unless content result = {} locales.each do |locale| hash = flat_hash(YAML.safe_load(locale.data)).transform_values { |v| JSON.encode(v) } result.merge! hash end result[key] end |
#[]=(key, value) ⇒ Object
48 49 50 |
# File 'lib/scribo/i18n_store.rb', line 48 def []=(key, value) # NOOP end |
#content ⇒ Object
60 61 62 |
# File 'lib/scribo/i18n_store.rb', line 60 def content Thread.current[:scribo_i18n_store_content] end |
#content=(content) ⇒ Object
64 65 66 |
# File 'lib/scribo/i18n_store.rb', line 64 def content=(content) Thread.current[:scribo_i18n_store_content] = content end |
#keys ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/scribo/i18n_store.rb', line 27 def keys return [] unless content result = [] locales.each do |locale| result += flat_hash(YAML.safe_load(locale.data)).keys end result end |
#with(content) ⇒ Object
52 53 54 55 56 57 58 |
# File 'lib/scribo/i18n_store.rb', line 52 def with(content) with_custom_backend do self.content = content yield(content) self.content = nil end end |