Class: ActiveRecord::Associations::Builder::Association
- Inherits:
-
Object
- Object
- ActiveRecord::Associations::Builder::Association
- Defined in:
- lib/activerecord_reindex/association.rb
Class Method Summary collapse
-
.define_callbacks(model, reflection) ⇒ Object
This method monkeypatches ActiveRecord define_callbacks to add reindex callbacks if corresponding option specified if reindex; true - add syncronous callback to reindex associated records if reindex: :async - add asyncronous callback to reindex associated records.
- .original_define_callbacks ⇒ Object
- .original_valid_options_ar_reindex ⇒ Object
-
.valid_options(*args) ⇒ Object
This method monkey patches ActiveRecord valid_options to add one more valid option :reindex Examples: belongs_to :tag, reindex: true belongs_to :tagging, reindex: :async has_many :tags, reindex: async has_many :tags, through: :taggings, reindex: true.
Class Method Details
.define_callbacks(model, reflection) ⇒ Object
This method monkeypatches ActiveRecord define_callbacks to add reindex callbacks if corresponding option specified if reindex; true - add syncronous callback to reindex associated records if reindex: :async - add asyncronous callback to reindex associated records
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/activerecord_reindex/association.rb', line 38 def define_callbacks(model, reflection) original_define_callbacks(model, reflection) if reflection.reindex_sync? add_reindex_callback(model, reflection, async: false) model.sync_reindexable_reflections += [reflection] elsif reflection.reindex_async? add_reindex_callback(model, reflection, async: true) model.async_reindexable_reflections += [reflection] end end |
.original_define_callbacks ⇒ Object
32 |
# File 'lib/activerecord_reindex/association.rb', line 32 alias original_define_callbacks define_callbacks |
.original_valid_options_ar_reindex ⇒ Object
20 |
# File 'lib/activerecord_reindex/association.rb', line 20 alias |
.valid_options(*args) ⇒ Object
This method monkey patches ActiveRecord valid_options to add one more valid option :reindex Examples:
belongs_to :tag, reindex: true
belongs_to :tagging, reindex: :async
has_many :tags, reindex: async
has_many :tags, through: :taggings, reindex: true
28 29 30 |
# File 'lib/activerecord_reindex/association.rb', line 28 def (*args) (*args) + [:reindex] end |