Created
January 25, 2012 14:20
-
-
Save christian-schulze/1676468 to your computer and use it in GitHub Desktop.
DCI example where a single user has two roles
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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