ruby - Injecting custom callback in rails 3 -


i have custom module sets hash stored in sql. part of rolls own _changed accessor.

module myawesomecustommodule    extend activesupport::concern     included       after_save: wipe_preferences_changed    end     module classmethods       def blah       end       etc    end end 

and in model:

class mymodel < activerecord::base    include myawesomecustommodule     after_save :something_that_expects_preferences_changed_to_be_available     blah end 

unfortunately, after_save defined in custom module runs before 1 defined in model. there way array of callbacks , append it? there way write custom after_after_save callback? there way specify priority/ordering of after_save callbacks?

what way resolve race condition?

in spite of order of model callbacks, current design makes module , class coupled.

to solve current problem improve design, can define expected callback in module's method, , class includes module free respond or not.

module myawesomecustommodule   extend activesupport::concern    included     after_save: wipe_preferences_changed   end    def wipe_preferences_changed     # previous logic wipe     process_further if respond_to :process_further   end end  class mymodel < activerecord::base   include myawesomecustommodule    # feel free write or not   # content previous    # :something_that_expects_preferences_changed_to_be_available   def process_further   end end 

Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -