Skip to content

Instantly share code, notes, and snippets.

@joecannatti
Created July 8, 2011 06:59
Show Gist options
  • Save joecannatti/1071280 to your computer and use it in GitHub Desktop.
Save joecannatti/1071280 to your computer and use it in GitHub Desktop.
conflicting prince
class SessionsController
def create
user = log_in_user
user.send_current_notifications!
end
def log_in_user
account = #sign in with params
UserFactory.user_for_account(account)
end
end
class Account < ActiveRecord::Base
end
class User
attr_accessor :account
def initialize(accout)
self.account = account
end
def has_access?
true
end
def send_current_notifications!
#blank here, but probably delegating to something
#else in a more complex example
end
end
class DisabledUser < User
def has_access?
false
end
def send_current_notifications!
account.send_disabled_notification!
end
end
class UserFactory
def self.user_for_account(account)
class_for_account(account).send(:new, account)
end
private
def self.class_for_account(account)
account.all_cards_invalid? ? DisabledUser : User
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment