Module: Wakari::Proxy::Model
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/wakari/models/proxy/model.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
- #available_langs ⇒ Object
- #current_translation ⇒ Object
- #default_translation ⇒ Object
- #detect_current_translation ⇒ Object
- #detect_translation(locale) ⇒ Object
- #possible_langs ⇒ Object
- #to_s(locale = nil) ⇒ Object
- #translation(locale) ⇒ Object
- #translation?(locale) ⇒ Boolean
- #translations_attributes ⇒ Object
- #used_langs ⇒ Object
Instance Method Details
#available_langs ⇒ Object
56 57 58 |
# File 'lib/wakari/models/proxy/model.rb', line 56 def available_langs possible_langs - used_langs end |
#current_translation ⇒ Object
80 81 82 |
# File 'lib/wakari/models/proxy/model.rb', line 80 def current_translation translation?(current_locale)||translations.first end |
#default_translation ⇒ Object
60 61 62 |
# File 'lib/wakari/models/proxy/model.rb', line 60 def default_translation translations.min_by {|t| t.position} end |
#detect_current_translation ⇒ Object
84 85 86 |
# File 'lib/wakari/models/proxy/model.rb', line 84 def detect_current_translation detect_translation(current_locale) end |
#detect_translation(locale) ⇒ Object
76 77 78 |
# File 'lib/wakari/models/proxy/model.rb', line 76 def detect_translation(locale) find_or_build_translation(:locale => locale) end |
#possible_langs ⇒ Object
48 49 50 |
# File 'lib/wakari/models/proxy/model.rb', line 48 def possible_langs translations.klass._locales end |
#to_s(locale = nil) ⇒ Object
88 89 90 |
# File 'lib/wakari/models/proxy/model.rb', line 88 def to_s(locale = nil) (locale ? translation?(locale) : current_translation).try(:to_s) end |
#translation(locale) ⇒ Object
64 65 66 |
# File 'lib/wakari/models/proxy/model.rb', line 64 def translation(locale) find_translation(:locale => locale) end |
#translation?(locale) ⇒ Boolean
68 69 70 71 72 73 74 |
# File 'lib/wakari/models/proxy/model.rb', line 68 def translation?(locale) begin translation(locale) rescue TranslationNotFound nil end end |
#translations_attributes ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/wakari/models/proxy/model.rb', line 40 def translations_attributes Hash[translations.map do |t| if (lang = t.lang) && (attributes = t.).present? [lang.to_method, attributes] end end.compact] end |
#used_langs ⇒ Object
52 53 54 |
# File 'lib/wakari/models/proxy/model.rb', line 52 def used_langs translations.map {|t| t.lang} end |