module Touch::ClassMethods
Public Instance Methods
touch(association_name, options = {})
click to toggle source
# File lib/touch.rb, line 8 def touch(association_name, options = {}) options = options.dup options.reverse_merge!(on: %w[create update destroy]) options[:on].map!(&:to_s) options[:on].each do |event| add_collection_touch_for(association_name, event) end end
Private Instance Methods
add_collection_touch_for(association_name, event)
click to toggle source
# File lib/touch.rb, line 20 def add_collection_touch_for(association_name, event) class_eval <<-RUBY, __FILE__, __LINE__ + 1 def collection_touch_event_for_#{association_name}_on_#{event} parent = public_send(:#{association_name}) field_name = "\#{self.class.model_name.cache_key}_updated_at" parent.try(:touch, field_name) end after_#{event} :collection_touch_event_for_#{association_name}_on_#{event} RUBY end