Skip to content

Instantly share code, notes, and snippets.

@aaronmcadam
Created May 13, 2014 11:49
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 aaronmcadam/72c43ec6f86922eac3ee to your computer and use it in GitHub Desktop.
Save aaronmcadam/72c43ec6f86922eac3ee to your computer and use it in GitHub Desktop.
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