Class: Multilang::MultilangTranslationKeeper
- Inherits:
-
Object
- Object
- Multilang::MultilangTranslationKeeper
- Defined in:
- lib/multilang-hstore/translation_keeper.rb
Instance Attribute Summary collapse
-
#attribute ⇒ Object
readonly
Returns the value of attribute attribute.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#translations ⇒ Object
readonly
Returns the value of attribute translations.
Instance Method Summary collapse
- #[](locale) ⇒ Object
- #[]=(locale, value) ⇒ Object
- #current_or_any_value ⇒ Object
- #empty? ⇒ Boolean
-
#initialize(model, attribute) ⇒ MultilangTranslationKeeper
constructor
A new instance of MultilangTranslationKeeper.
- #locales ⇒ Object
- #to_s ⇒ Object
- #to_str(locale = nil) ⇒ Object
- #update(value) ⇒ Object
- #value(locale = nil) ⇒ Object
Constructor Details
#initialize(model, attribute) ⇒ MultilangTranslationKeeper
Returns a new instance of MultilangTranslationKeeper.
8 9 10 11 12 13 |
# File 'lib/multilang-hstore/translation_keeper.rb', line 8 def initialize(model, attribute) @model = model @attribute = attribute @translations = {} load! end |
Instance Attribute Details
#attribute ⇒ Object (readonly)
Returns the value of attribute attribute.
5 6 7 |
# File 'lib/multilang-hstore/translation_keeper.rb', line 5 def attribute @attribute end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
4 5 6 |
# File 'lib/multilang-hstore/translation_keeper.rb', line 4 def model @model end |
#translations ⇒ Object (readonly)
Returns the value of attribute translations.
6 7 8 |
# File 'lib/multilang-hstore/translation_keeper.rb', line 6 def translations @translations end |
Instance Method Details
#[](locale) ⇒ Object
42 43 44 |
# File 'lib/multilang-hstore/translation_keeper.rb', line 42 def [](locale) read(locale) end |
#[]=(locale, value) ⇒ Object
46 47 48 49 |
# File 'lib/multilang-hstore/translation_keeper.rb', line 46 def []=(locale, value) write(locale, value) flush! end |
#current_or_any_value ⇒ Object
19 20 21 |
# File 'lib/multilang-hstore/translation_keeper.rb', line 19 def current_or_any_value @translations.current_or_any_value end |
#empty? ⇒ Boolean
55 56 57 |
# File 'lib/multilang-hstore/translation_keeper.rb', line 55 def empty? @translations.empty? end |
#locales ⇒ Object
51 52 53 |
# File 'lib/multilang-hstore/translation_keeper.rb', line 51 def locales @translations.locales end |
#to_s ⇒ Object
23 24 25 |
# File 'lib/multilang-hstore/translation_keeper.rb', line 23 def to_s raw_read(actual_locale) end |
#to_str(locale = nil) ⇒ Object
27 28 29 30 |
# File 'lib/multilang-hstore/translation_keeper.rb', line 27 def to_str(locale = nil) locale ||= actual_locale raw_read(locale) end |
#update(value) ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'lib/multilang-hstore/translation_keeper.rb', line 32 def update(value) if value.is_a?(Hash) clear value.each{|k, v| write(k, v)} elsif value.is_a?(String) write(actual_locale, value) end flush! end |
#value(locale = nil) ⇒ Object
15 16 17 |
# File 'lib/multilang-hstore/translation_keeper.rb', line 15 def value(locale = nil) @translations.value(locale) end |