Sha256: c23ec34980974ac28e1c1d5f7ce56a2646a9b9fd216419818b42559d7834b758
Contents?: true
Size: 1.43 KB
Versions: 2
Compression:
Stored size: 1.43 KB
Contents
module ActiveGit class DbEvent def initialize(file_name, working_path=nil) @file_name = file_name @working_path = working_path || ActiveGit.configuration.working_path end private def model @model ||= Inflector.model(@file_name, @working_path) end def model_id Inflector.model_id @file_name end def create(synchronizer) json = File.read @file_name ModelParser.instances(model, json).each do |instance| synchronizer.bulk_insert instance end end def delete(synchronizer) synchronizer.define_job do instance = model.find_by_id(model_id) if instance model.git_included_associations.each do |a| if association = instance.reflections[a] if association.collection? instance.send(a).each do |e| ActiveGit.configuration.logger.debug "[ActiveGit] Deleting #{e.class.model_name} #{e.id}" e.delete end else if i = instance.send(a) ActiveGit.configuration.logger.debug "[ActiveGit] Deleting #{i.class.model_name} #{i.id}" instance.send(a).delete end end end end ActiveGit.configuration.logger.debug "[ActiveGit] Deleting #{model.model_name} #{model_id}" instance.delete end end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
active_git-0.0.10 | lib/active_git/events/db_event.rb |
active_git-0.0.9 | lib/active_git/events/db_event.rb |