Class: Multilang::MultilangTranslationKeeper

Inherits:
Object
  • Object
show all
Defined in:
lib/multilang-hstore/translation_keeper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#attributeObject (readonly)

Returns the value of attribute attribute.



5
6
7
# File 'lib/multilang-hstore/translation_keeper.rb', line 5

def attribute
  @attribute
end

#modelObject (readonly)

Returns the value of attribute model.



4
5
6
# File 'lib/multilang-hstore/translation_keeper.rb', line 4

def model
  @model
end

#translationsObject (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_valueObject



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

Returns:

  • (Boolean)


55
56
57
# File 'lib/multilang-hstore/translation_keeper.rb', line 55

def empty?
  @translations.empty?
end

#localesObject



51
52
53
# File 'lib/multilang-hstore/translation_keeper.rb', line 51

def locales
  @translations.locales
end

#to_sObject



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