Skip to content

Instantly share code, notes, and snippets.

@sarahmei
Forked from anonymous/gist:812044
Created February 5, 2011 00:05
Show Gist options
  • Save sarahmei/812045 to your computer and use it in GitHub Desktop.
Save sarahmei/812045 to your computer and use it in GitHub Desktop.
module HasPersonProxy
module ClassMethods
def always_has_person
self.instance_eval do
include InstanceMethods
alias_method_chain :person, :proxy
end
end
end
module InstanceMethods
def person_with_proxy
self.person_without_proxy || DeletedPersonProxy.new(self)
end
end
class DeletedPersonProxy
def initialize(object=nil)
unless object.nil?
Rails.logger.info("event=person_proxy object=#{object.class} object_id=#{object.id} deleted_person_id=#{object.person_id} ")
end
@empty = ''
@h = '#'
end
#def id
# @h
#end
def name
'Diaspora User'
end
def owner_id
nil
end
def method_missing(*args)
@empty
end
end
def self.included(base)
base.class_eval do
base.extend ClassMethods
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment