module Safubot # General identity cache. Extended by service-specific modules. # A single class in order to allow linking of identity between services. class KnownUser include MongoMapper::Document safe many :requests, :as => "user", :class_name => "Safubot::Request" timestamps! # Combines the service-specific identities of two users to # form a cohesive picture of an individual. def merge(user) self.keys.keys.each do |key| Log.info "#{key.inspect} #{self[key].inspect} #{user[key].inspect}" self[key] = user[key] if self[key].nil? || (self[key].respond_to?(:empty?) && self[key].empty?) end user.requests.each do |req| req.user = self; req.save! end save! user.destroy end end end