Skip to content

Instantly share code, notes, and snippets.

@christian-schulze
Created January 25, 2012 14:20
Show Gist options
  • Save christian-schulze/1676468 to your computer and use it in GitHub Desktop.
Save christian-schulze/1676468 to your computer and use it in GitHub Desktop.
DCI example where a single user has two roles
# DCI example where a single user has two roles
class AuthorizeEmployeeDiscount
attr_accessor :employee, :manager
def self.execute(employee_user_id, manager_user_id)
AuthorizeEmployeeDiscount.new(employee_user_id, manager_user_id).execute
end
def initialize(employee_user_id, manager_user_id)
@employee = User.find(employee_user_id)
@manager = User.find(manager_user_id)
@manager.extend DiscountAuthorizor
end
def execute
@manager.authorize_discount(@employee)
end
end
employee_user_id = 999
manager_user_id = 999
AuthorizeEmployeeDiscount.execute employee_user_id, manager_user_id
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment