Class: Lolita::Translation::Record
- Inherits:
-
Object
- Object
- Lolita::Translation::Record
- Defined in:
- lib/lolita-translation/record.rb
Defined Under Namespace
Classes: ARRecord, AbstractRecord, MongoidRecord
Instance Attribute Summary collapse
-
#default_locale ⇒ Object
Returns the value of attribute default_locale.
-
#original_record ⇒ Object
readonly
Returns the value of attribute original_record.
-
#orm_wrapper ⇒ Object
readonly
Returns the value of attribute orm_wrapper.
Instance Method Summary collapse
- #attribute(name) ⇒ Object
- #build_nested_translations ⇒ Object
- #in(locale) ⇒ Object
-
#initialize(original_record, configuration = nil) ⇒ Record
constructor
A new instance of Record.
- #system_current_locale ⇒ Object
Constructor Details
#initialize(original_record, configuration = nil) ⇒ Record
Returns a new instance of Record.
143 144 145 146 147 148 149 |
# File 'lib/lolita-translation/record.rb', line 143 def initialize(original_record, configuration = nil) @configuration = configuration @original_record = original_record @orm_wrapper = get_orm_wrapper @default_locale = @orm_wrapper.locale @record_current_locale = nil end |
Instance Attribute Details
#default_locale ⇒ Object
Returns the value of attribute default_locale.
141 142 143 |
# File 'lib/lolita-translation/record.rb', line 141 def default_locale @default_locale end |
#original_record ⇒ Object (readonly)
Returns the value of attribute original_record.
141 142 143 |
# File 'lib/lolita-translation/record.rb', line 141 def original_record @original_record end |
#orm_wrapper ⇒ Object (readonly)
Returns the value of attribute orm_wrapper.
141 142 143 |
# File 'lib/lolita-translation/record.rb', line 141 def orm_wrapper @orm_wrapper end |
Instance Method Details
#attribute(name) ⇒ Object
151 152 153 154 155 156 157 |
# File 'lib/lolita-translation/record.rb', line 151 def attribute(name) if default_locale.to_s == current_locale.to_s @orm_wrapper.attribute(name) else @orm_wrapper.translated_attribute(name, :locale => current_locale) end end |
#build_nested_translations ⇒ Object
159 160 161 162 163 164 165 166 |
# File 'lib/lolita-translation/record.rb', line 159 def build_nested_translations available_locales.each do |locale| unless self.default_locale.to_s == locale.to_s attributes = { :locale => locale.to_s } original_record.translations.build(attributes) unless orm_wrapper.has_translation_for?(locale) end end end |
#in(locale) ⇒ Object
172 173 174 175 176 177 178 179 180 181 |
# File 'lib/lolita-translation/record.rb', line 172 def in(locale) old_locale = @record_current_locale @record_current_locale = locale if block_given? yield(self.original_record) @record_current_locale = old_locale else self.original_record end end |
#system_current_locale ⇒ Object
183 184 185 |
# File 'lib/lolita-translation/record.rb', line 183 def system_current_locale ::I18n.locale end |