module MissHannigan::ClassMethods
Public Instance Methods
connect_nullify_then_purge(reflection, name)
click to toggle source
# File lib/miss_hannigan/miss_hannigan.rb, line 28 def connect_nullify_then_purge(reflection, name) # has the details of the relation to Child reflection_details = reflection[name.to_s] # I bet folks are going to forget to do the migration of foreign_keys to accept null. Rails defaults # to not allow null. if !reflection_details.klass.columns.find { |c| c.name == reflection_details.foreign_key }.null raise "The foreign key must be nullable to support MissHannigan. You should create a migration to: change_column_null :#{name.to_s}, :#{reflection_details.foreign_key}, true" end after_destroy do |this_object| CleanupJob.perform_later(reflection_details.klass.to_s, reflection_details.foreign_key) end end
detect_nullify_then_purge(options)
click to toggle source
# File lib/miss_hannigan/miss_hannigan.rb, line 19 def detect_nullify_then_purge(options) if options[:dependent] == :nullify_then_purge options[:dependent] = :nullify true else false end end
has_many(name, scope = nil, **options, &extension)
click to toggle source
Calls superclass method
# File lib/miss_hannigan/miss_hannigan.rb, line 5 def has_many(name, scope = nil, **options, &extension) nullify_then_purge = detect_nullify_then_purge(options) super.tap do |reflection| connect_nullify_then_purge(reflection, name) if nullify_then_purge end end
has_one(name, scope = nil, **options, &extension)
click to toggle source
Calls superclass method
# File lib/miss_hannigan/miss_hannigan.rb, line 12 def has_one(name, scope = nil, **options, &extension) nullify_then_purge = detect_nullify_then_purge(options) super.tap do |reflection| connect_nullify_then_purge(reflection, name) if nullify_then_purge end end