Class: Mobility::Backends::ActionText
- Inherits:
-
ActiveRecord::KeyValue
- Object
- ActiveRecord::KeyValue
- Mobility::Backends::ActionText
- Defined in:
- lib/mobility/backends/action_text.rb
Overview
Implements the KeyValue backend for ActionText.
Defined Under Namespace
Modules: ActionTextValidations, WithAllRichText Classes: PlainTextTranslation, RichTextTranslation
Backend Configuration collapse
Class Method Summary collapse
-
.define_after_destroy_callback(klass) ⇒ Object
override destroy logic because we are not using the db tables from the subclassed KeyValue implementation.
- .valid_keys ⇒ Object
Instance Method Summary collapse
-
#read(locale, **options) ⇒ Object
override to return record instead of value.
Class Method Details
.configure(options) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/mobility/backends/action_text.rb', line 47 def configure() [:plain] = false unless .has_key?(:plain) if [:plain] [:association_name] ||= 'plain_text_translations' [:class_name] ||= PlainTextTranslation else [:association_name] ||= 'rich_text_translations' [:class_name] ||= RichTextTranslation end [:key_column] ||= :name [:value_column] ||= :body [:belongs_to] ||= :record super end |
.define_after_destroy_callback(klass) ⇒ Object
override destroy logic because we are not using the db tables from the subclassed KeyValue implementation
65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/mobility/backends/action_text.rb', line 65 def define_after_destroy_callback(klass) # Ensure we only call after destroy hook once per translations class b = self translation_classes = [class_name, RichTextTranslation, PlainTextTranslation].uniq klass.after_destroy do @mobility_after_destroy_translation_classes = [] unless defined?(@mobility_after_destroy_translation_classes) (translation_classes - @mobility_after_destroy_translation_classes).each do |translation_class| translation_class.where(b.belongs_to => self).destroy_all end @mobility_after_destroy_translation_classes += translation_classes end end |
.valid_keys ⇒ Object
41 42 43 |
# File 'lib/mobility/backends/action_text.rb', line 41 def valid_keys super.tap { |keys| keys.delete(:type) } << :plain end |
Instance Method Details
#read(locale, **options) ⇒ Object
override to return record instead of value
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/mobility/backends/action_text.rb', line 29 def read(locale, **) return super if self.[:plain] if model.association_cached?("rich_text_#{attribute}") eager_loaded = model.public_send("rich_text_#{attribute}") return eager_loaded if eager_loaded.locale == locale.to_s end translation_for(locale, **) end |