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 ⇒ 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
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/activerecord_reindex/association.rb', line 37 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
31 |
# File 'lib/activerecord_reindex/association.rb', line 31 alias original_define_callbacks define_callbacks |
.original_valid_options ⇒ Object
19 |
# File 'lib/activerecord_reindex/association.rb', line 19 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
27 28 29 |
# File 'lib/activerecord_reindex/association.rb', line 27 def (*args) (*args) + [:reindex] end |