Create a setter method for key in an anonymous module included in the class that calls super and clears the cache for the given array of associations.
# File lib/sequel/plugins/association_autoreloading.rb, line 21 21: def create_autoreloading_association_setter(key, assocs) 22: include(@autoreloading_associations_module ||= Module.new) unless @autoreloading_associations_module 23: @autoreloading_associations_module.class_eval do 24: unless method_defined?("#{key}=") 25: define_method("#{key}=") do |v| 26: o = send(key) 27: super(v) 28: assocs.each{|a| associations.delete(a)} if send(key) != o 29: end 30: end 31: end 32: end
For each of the foreign keys in the association, create a setter method that will clear the association cache.
# File lib/sequel/plugins/association_autoreloading.rb, line 36 36: def def_many_to_one(opts) 37: super 38: @autoreloading_associations ||= {} 39: opts[:keys].each do |key| 40: assocs = @autoreloading_associations[key] ||= [] 41: assocs << opts[:name] 42: create_autoreloading_association_setter(key, assocs) 43: end 44: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.