Module: Globalize::ActiveRecord::InstanceMethods
- Defined in:
- lib/globalize/active_record.rb
Instance Method Summary collapse
- #attribute_names ⇒ Object
- #attributes ⇒ Object
- #attributes=(attributes, *args) ⇒ Object
- #available_locales ⇒ Object
- #globalize ⇒ Object
- #reload(options = nil) ⇒ Object
- #set_translations(options) ⇒ Object
- #translated_attributes ⇒ Object
- #translated_locales ⇒ Object
Instance Method Details
#attribute_names ⇒ Object
173 174 175 |
# File 'lib/globalize/active_record.rb', line 173 def attribute_names translated_attribute_names.map(&:to_s) + super end |
#attributes ⇒ Object
157 158 159 160 161 162 163 |
# File 'lib/globalize/active_record.rb', line 157 def attributes self.attribute_names.inject({}) do |attrs, name| attrs[name] = read_attribute(name) || (globalize.fetch(I18n.locale, name) rescue nil) attrs end end |
#attributes=(attributes, *args) ⇒ Object
165 166 167 168 169 170 171 |
# File 'lib/globalize/active_record.rb', line 165 def attributes=(attributes, *args) if attributes.respond_to?(:delete) && locale = attributes.delete(:locale) self.class.with_locale(locale) { super } else super end end |
#available_locales ⇒ Object
177 178 179 |
# File 'lib/globalize/active_record.rb', line 177 def available_locales translations.scoped(:select => 'DISTINCT locale').map(&:locale) end |
#globalize ⇒ Object
153 154 155 |
# File 'lib/globalize/active_record.rb', line 153 def globalize @globalize ||= Adapter.new self end |
#reload(options = nil) ⇒ Object
199 200 201 202 203 |
# File 'lib/globalize/active_record.rb', line 199 def reload( = nil) translated_attribute_names.each { |name| @attributes.delete(name.to_s) } globalize.reset super() end |
#set_translations(options) ⇒ Object
191 192 193 194 195 196 197 |
# File 'lib/globalize/active_record.rb', line 191 def set_translations() .keys.each do |locale| translation = translations.find_by_locale(locale.to_s) || translations.build(:locale => locale.to_s) translation.update_attributes!([locale]) end end |
#translated_attributes ⇒ Object
185 186 187 188 189 |
# File 'lib/globalize/active_record.rb', line 185 def translated_attributes translated_attribute_names.inject({}) do |attributes, name| attributes.merge(name => send(name)) end end |
#translated_locales ⇒ Object
181 182 183 |
# File 'lib/globalize/active_record.rb', line 181 def translated_locales translations.map(&:locale) end |