Skip to content

Instantly share code, notes, and snippets.

@andrzejkrzywda
Last active December 15, 2015 01:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrzejkrzywda/5178595 to your computer and use it in GitHub Desktop.
Save andrzejkrzywda/5178595 to your computer and use it in GitHub Desktop.
class Company
def initialize
@employees = []
@roles = {}
end
def delegate(from_employee, task, to_employee)
raise TargetEmployeerDoesntHaveTheRequiredRole if ! has_role?(to_employee, task.required_role)
from_employee.remove_task(task)
to_employee.add_task(task)
end
def assign_role(employee, role)
@roles[employee] << role
end
def hire_employee(employee)
@employees << employee
@roles[employee] = []
end
def has_role?(employee, role)
@roles[employee].include?(role)
end
def add_task(task, employee)
employee.add_task(task)
end
end
class Employee
def initialize
@tasks = []
end
def add_task(task)
@tasks << task
end
def remove_task(task)
@tasks.delete(task)
end
end
class Task
attr_reader :required_role
def initialize
@required_role = nil
end
def requires(role)
@required_role = role
end
end
class Role
end
arkency = Company.new
andrzej = Employee.new
robert = Employee.new
arkency.hire_employee(andrzej)
arkency.hire_employee(robert)
devop = Role.new
arkency.assign_role(andrzej, devop)
arkency.assign_role(robert, devop)
infra_checklist = Task.new
infra_checklist.requires(devop)
arkency.add_task(infra_checklist, andrzej)
arkency.delegate(andrzej, infra_checklist, robert)
puts andrzej.inspect
puts robert.inspect
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment