Created
May 28, 2012 09:46
-
-
Save mech/2818221 to your computer and use it in GitHub Desktop.
Domain Driven Recruitment Pipeline
This file contains hidden or 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
| class RecruitmentPipeline | |
| end | |
| # Stage is a progression or step on a candidate's job application. | |
| # It represents the state the application is in and offers several | |
| # statistic on the effectiveness of consultant at this stage. | |
| # | |
| # For example, Stage 1 might be AppliedStage, or NewStage | |
| # depending on whether candidate applied himself or consultant | |
| # selected him. | |
| class Stage | |
| include StateMachine | |
| def initialize(pipeline) | |
| @pipeline = pipeline | |
| end | |
| def log | |
| candidate = pipeline.candidate | |
| consultant = pipeline.consultant | |
| message = i18n(:applied, candidate, consultant) | |
| write_to_log_db(message) | |
| end | |
| def duration | |
| previous_stage.timestamp - timestamp | |
| end | |
| def previous_stage | |
| # Using a nil safe object to find out the previous | |
| # stage. If nil, calling #timestamp will be no-op | |
| end | |
| def next_stage | |
| # why not? since we have previous stage, we might as well | |
| # present what's the next stage for this particular stage | |
| end | |
| def timestamp | |
| # snip | |
| end | |
| private | |
| def write_to_log_db | |
| # snip | |
| end | |
| end | |
| class AppliedStage < Stage | |
| common_name :applied | |
| transition_to :reviewed | |
| end | |
| class SubmittedStage < Stage | |
| common_name :submitted | |
| transition_to :rejected, :interview, :offered | |
| end | |
| @pipeline.stages | |
| @pipeline.stages[:applied] | |
| @pipeline.stages[:submitted].duration # => 3 hours, which tells us that consultant took 3 hours to submit application |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment