Created
May 13, 2014 11:49
-
-
Save aaronmcadam/72c43ec6f86922eac3ee to your computer and use it in GitHub Desktop.
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
class Repository | |
extend Forwardable | |
attr_reader :question, :task_list, :task | |
def_delegator :question, :id, :question_id | |
def_delegator :question, :alias, :question_alias | |
def_delegator :question, :summary, :question_summary | |
def_delegator :task, :id, :task_id | |
def_delegator :task, :type, :task_type | |
def_delegator :task, :title, :task_title | |
def_delegator :task, :description, :task_description | |
def_delegator :project, :id, :project_id | |
def_delegator :project, :title, :project_title | |
def initialize(question:, task:, task_list:) | |
@question = question | |
@task = task | |
@task_list = task_list | |
end | |
def project | |
@project ||= task_list.project | |
end | |
end | |
class RepositoryBuilder | |
attr_reader :repository | |
def initialize(question_id) | |
# This may look a bit weird, but I need to .find each of the models | |
# the Repository needs in order to get their parents | |
# | |
# The dependency graph is as follows: | |
# Project < Task List < Task < Question | |
question = Question.find_with_tags(question_id) | |
task = Task.find(question.task.id) | |
task_list = Crowdlab::Model::TaskList.find(task.task_list.id) | |
repository_options = { | |
question: question, task: task, task_list: task_list | |
} | |
@repository = Repository.new(repository_options) | |
end | |
end | |
class QuestionTagsController < ApplicationController | |
# ... | |
def set_breadcrumbs | |
@repo = RepositoryBuilder.new(params[:question_id]).repository | |
home_breadcrumb | |
add_breadcrumb(label: @repo.project_title, | |
link: project_path(@repo.project_id), | |
icon: "icon_project") | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment