Sha256: ed1b33c26133057d7af5b8a0f3958a08592626072ae3c65671c16fc39ae5d395

Contents?: true

Size: 750 Bytes

Versions: 8

Compression:

Stored size: 750 Bytes

Contents

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

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
safubot-0.0.9 lib/safubot/known_user.rb
safubot-0.0.8 lib/safubot/known_user.rb
safubot-0.0.7 lib/safubot/known_user.rb
safubot-0.0.6 lib/safubot/known_user.rb
safubot-0.0.5 lib/safubot/known_user.rb
safubot-0.0.4 lib/safubot/known_user.rb
safubot-0.0.3 lib/safubot/known_user.rb
safubot-0.0.2 lib/safubot/known_user.rb