Skip to content

Instantly share code, notes, and snippets.

@talum
talum / deploy_code_challenge.rb
Last active June 2, 2018 01:14
Assignments on Learn.co
class DeployCodeChallenge
attr_reader :git_source_url, :deployable_task, :deployer, :assignees, :errors
attr_accessor :deployed_repo_url
def initialize(git_source_url:, deployable_task:, deployer:, assignees:)
@git_source_url = git_source_url
@deployable_task = deployable_task
@deployer = to_deploying_user(deployer)
@assignees = to_github_collaborators(assignees)
@errors = []
{
assignment: {
id: 1,
title: 'Read Programming Phoenix',
description: 'Learn about Elixir and create a Phoenix app in the process!',
started_at: null,
due_at: null,
creator_id: 1,
created_at: '2018–02–13T20:32:29.178–05:00',
updated_at: '2018–02–13T20:32:29.178–05:00',
// defined in actions.js
export const modifyActiveAssignment = (attribute, value) => ({
type: MODIFY_ACTIVE_ASSIGNMENT,
payload: {
attribute,
value
}
})
// defined in the React component
// editorReducer.js
case MODIFY_ACTIVE_ASSIGNMENT:
const { attribute, value } = payload
return { …state, active: { …active, [attribute]: value } }
case ADD_TASK:
case SHOW_TASK:
case UPDATE_TASK:
case REMOVE_TASK:
const tasks = tasksReducer(active.tasks, action)
return { …state, active: { …active, tasks } }
module Assignments
# This code lives in a module that we use to namespace our application as part of domain-driven design. You might call this an aggregate root.
def self.update_assignment(assignment_id, title:, description:, collaborator_ids:, assignee_ids:, tasks:, due_in:, due_in_units:)
assignment = Assignment
.includes(tasks: :rubric_items)
.find(assignment_id)
assignment.update(
title: title,
description: description,
class Assignment < ActiveRecord:Base
# code omitted
def set_tasks_from_list(task_attributes)
self.tasks = self.tasks.new(task_attributes)
end
def set_collaborators_from_list(collaborator_ids)
collaborators = collaborator_ids.map { |id| { collaborator_id: id } }
self.collaborations = self.collaborations.new(collaborators)
class PublishableAssignmentValidation
attr_reader :assignment
def initialize(assignment)
@assignment = assignment
end
def valid?
validate
assignment.errors.none?
@talum
talum / sti_1a.rb
Last active November 25, 2018 19:07
STI examples
def completed_labs_count(student, canonical_repo_ids)
if $rollout.active?(:remove_content)
student.canonical_progresses.complete.
joins(github_repository: :canonical_material).
where(github_repository_id: canonical_repo_ids).
where(kind: CourseWork::CanonicalMaterial::LAB_KINDS).
uniq(:id).
count
else
student.canonical_progresses.complete.
@talum
talum / sti_1b.rb
Last active November 25, 2018 19:09
# some other caller
def set_projects_progress_status!
project_repo_ids = AssignedRepo.team_projects_for(batch_id: batch.id, track_id: track.id).pluck(:canonical_id)
end
def set_projects_progress_status!
project_repo_ids = AssignedRepo.team_projects_for(batch_id: batch.id, track_id: track.id).canonical_github_repository_ids
end
# Assigned Repo
class Api::V1::SearchesController < ApiController
def new
gh_id_mappings = if $rollout.active?(:remove_content)
GithubRepository.track_data_for_github_repos(repos.pluck(:id), current_user.active_track_id)
else
GithubRepository.github_id_mappings_for_global_search(current_user)
end
# omitted
end