RuboCop: Style/EachWithObject
auto-corrected Change-Id: I3f1a71b7b521b9cd7ddc37f4460d83855c93001f Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/278777 Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com> Reviewed-by: Jacob Burroughs <jburroughs@instructure.com> QA-Review: Cody Cutrer <cody@instructure.com> Product-Review: Cody Cutrer <cody@instructure.com>
This commit is contained in:
parent
f5a4bfe1bc
commit
5851dc6497
|
@ -203,6 +203,8 @@ Style/Dir:
|
|||
Severity: error
|
||||
Style/Documentation:
|
||||
Enabled: false # most things don't need to be documented
|
||||
Style/EachWithObject:
|
||||
Severity: error
|
||||
Style/EmptyCaseCondition:
|
||||
Severity: error
|
||||
Style/Encoding:
|
||||
|
|
|
@ -1567,10 +1567,9 @@ class AccountsController < ApplicationController
|
|||
|
||||
teachers = TeacherEnrollment.for_courses_with_user_name(courses_to_fetch_users_for).where.not(:enrollments => { :workflow_state => %w{rejected deleted} })
|
||||
course_to_student_counts = StudentEnrollment.student_in_claimed_or_available.where(:course_id => courses_to_fetch_users_for).group(:course_id).distinct.count(:user_id)
|
||||
courses_to_teachers = teachers.inject({}) do |result, teacher|
|
||||
courses_to_teachers = teachers.each_with_object({}) do |teacher, result|
|
||||
result[teacher.course_id] ||= []
|
||||
result[teacher.course_id] << teacher
|
||||
result
|
||||
end
|
||||
courses_to_fetch_users_for.each do |course|
|
||||
course.student_count = course_to_student_counts[course.id] || 0
|
||||
|
|
|
@ -2067,9 +2067,8 @@ class ApplicationController < ActionController::Base
|
|||
|
||||
def conversations_path(params = {})
|
||||
if @current_user
|
||||
query_string = params.slice(:context_id, :user_id, :user_name).inject([]) do |res, (k, v)|
|
||||
query_string = params.slice(:context_id, :user_id, :user_name).each_with_object([]) do |(k, v), res|
|
||||
res << "#{k}=#{v}"
|
||||
res
|
||||
end.join('&')
|
||||
"/conversations?#{query_string}"
|
||||
else
|
||||
|
|
|
@ -1275,7 +1275,7 @@ class CalendarEventsApiController < ApplicationController
|
|||
end
|
||||
|
||||
courses_user_has_been_enrolled_in = DatesOverridable.precache_enrollments_for_multiple_assignments(events, user)
|
||||
events = events.inject([]) do |assignments, assignment|
|
||||
events = events.each_with_object([]) do |assignment, assignments|
|
||||
if courses_user_has_been_enrolled_in[:student].include?(assignment.context_id)
|
||||
assignment = assignment.overridden_for(user)
|
||||
assignment.infer_all_day(Time.zone)
|
||||
|
@ -1303,7 +1303,6 @@ class CalendarEventsApiController < ApplicationController
|
|||
end
|
||||
end
|
||||
end
|
||||
assignments
|
||||
end
|
||||
|
||||
if !@all_events && !@undated
|
||||
|
|
|
@ -179,11 +179,10 @@ class ContextController < ApplicationController
|
|||
@services = @services.select { |service|
|
||||
feature_and_service_enabled?(service.service.to_sym)
|
||||
}
|
||||
@services_hash = @services.to_a.inject({}) do |hash, item|
|
||||
@services_hash = @services.to_a.each_with_object({}) do |item, hash|
|
||||
mapped = item.service
|
||||
hash[mapped] ||= []
|
||||
hash[mapped] << item
|
||||
hash
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -33,14 +33,13 @@ class ContextModulesController < ApplicationController
|
|||
|
||||
def load_module_file_details
|
||||
attachment_tags = GuardRail.activate(:secondary) { @context.module_items_visible_to(@current_user).where(content_type: 'Attachment').preload(:content => :folder).to_a }
|
||||
attachment_tags.inject({}) do |items, file_tag|
|
||||
attachment_tags.each_with_object({}) do |file_tag, items|
|
||||
items[file_tag.id] = {
|
||||
id: file_tag.id,
|
||||
content_id: file_tag.content_id,
|
||||
content_details: content_details(file_tag, @current_user, :for_admin => true),
|
||||
module_id: file_tag.context_module_id
|
||||
}
|
||||
items
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -3570,7 +3570,7 @@ class CoursesController < ApplicationController
|
|||
changes.delete("settings") if changes.key?("settings")
|
||||
|
||||
unless old_settings == new_settings
|
||||
settings = Course.settings_options.keys.inject({}) do |results, key|
|
||||
settings = Course.settings_options.keys.each_with_object({}) do |key, results|
|
||||
old_value = if old_settings.present? && old_settings.key?(key)
|
||||
old_settings[key]
|
||||
else
|
||||
|
@ -3584,8 +3584,6 @@ class CoursesController < ApplicationController
|
|||
end
|
||||
|
||||
results[key.to_s] = [old_value, new_value] unless old_value == new_value
|
||||
|
||||
results
|
||||
end
|
||||
changes.merge!(settings)
|
||||
end
|
||||
|
|
|
@ -738,9 +738,8 @@ class MasterCourses::MasterTemplatesController < ApplicationController
|
|||
@mm.master_template.content_tags.where(:migration_id => tags.map(&:migration_id))
|
||||
end
|
||||
|
||||
master_tags.inject(Set.new) do |ids, tag|
|
||||
master_tags.each_with_object(Set.new) do |tag, ids|
|
||||
ids << tag.migration_id if tag.restrictions&.values&.any?
|
||||
ids
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -137,12 +137,10 @@ class Quizzes::QuizSubmissionQuestionsController < ApplicationController
|
|||
reject! 'you are not allowed to update questions for this quiz submission', 403
|
||||
end
|
||||
|
||||
answers = params.to_unsafe_h.fetch(:quiz_questions, []).reduce({}) do |hsh, p|
|
||||
answers = params.to_unsafe_h.fetch(:quiz_questions, []).each_with_object({}) do |p, hsh|
|
||||
if p[:id].present?
|
||||
hsh[p[:id].to_i] = p[:answer] || []
|
||||
end
|
||||
|
||||
hsh
|
||||
end
|
||||
|
||||
quiz_questions = @quiz.quiz_questions.where(id: answers.keys)
|
||||
|
|
|
@ -72,7 +72,7 @@ module RollupScoreAggregatorHelper
|
|||
end
|
||||
|
||||
def get_aggregates(result)
|
||||
@outcome_results.reduce({ total: 0.0, weighted: 0.0 }) do |aggregate, lor|
|
||||
@outcome_results.each_with_object({ total: 0.0, weighted: 0.0 }) do |lor, aggregate|
|
||||
if is_match?(result, lor) && lor.possible
|
||||
aggregate[:total] += lor.possible
|
||||
begin
|
||||
|
@ -82,7 +82,6 @@ module RollupScoreAggregatorHelper
|
|||
raise e
|
||||
end
|
||||
end
|
||||
aggregate
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -1243,10 +1243,9 @@ class Account < ActiveRecord::Base
|
|||
shard.activate do
|
||||
all_site_admin_account_users_hash = MultiCache.fetch("all_site_admin_account_users3") do
|
||||
# this is a plain ruby hash to keep the cached portion as small as possible
|
||||
self.account_users.active.inject({}) { |result, au|
|
||||
self.account_users.active.each_with_object({}) { |au, result|
|
||||
result[au.user_id] ||= []
|
||||
result[au.user_id] << [au.id, au.role_id]
|
||||
result
|
||||
}
|
||||
end
|
||||
(all_site_admin_account_users_hash[user.id] || []).map do |(id, role_id)|
|
||||
|
|
|
@ -177,9 +177,8 @@ class AccountUser < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def self.is_subset_of?(user, account, role)
|
||||
needed_permissions = RoleOverride.manageable_permissions(account).keys.inject({}) do |result, permission|
|
||||
result[permission] = RoleOverride.enabled_for?(account, permission, role, account)
|
||||
result
|
||||
needed_permissions = RoleOverride.manageable_permissions(account).keys.index_with do |permission|
|
||||
RoleOverride.enabled_for?(account, permission, role, account)
|
||||
end
|
||||
target_permissions = AccountUser.all_permissions_for(user, account)
|
||||
needed_permissions.all? do |(permission, needed_permission)|
|
||||
|
|
|
@ -163,9 +163,8 @@ class AssessmentQuestion < ActiveRecord::Base
|
|||
deep_translate = lambda do |obj|
|
||||
case obj
|
||||
when Hash
|
||||
obj.inject(HashWithIndifferentAccess.new) { |h, (k, v)|
|
||||
obj.each_with_object(HashWithIndifferentAccess.new) { |(k, v), h|
|
||||
h[k] = deep_translate.call(v)
|
||||
h
|
||||
}
|
||||
when Array
|
||||
obj.map { |v| deep_translate.call(v) }
|
||||
|
|
|
@ -2625,10 +2625,9 @@ class Course < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def all_dates
|
||||
(self.calendar_events.active + self.assignments.active).inject([]) { |list, e|
|
||||
(self.calendar_events.active + self.assignments.active).each_with_object([]) { |e, list|
|
||||
list << e.end_at if e.end_at
|
||||
list << e.start_at if e.start_at
|
||||
list
|
||||
}.compact.flatten.map(&:to_date).uniq rescue []
|
||||
end
|
||||
|
||||
|
|
|
@ -540,11 +540,10 @@ class Folder < ActiveRecord::Base
|
|||
|
||||
# find all unlocked/visible folders that can be reached by following unlocked/visible folders from the root
|
||||
def self.all_visible_folder_ids(context)
|
||||
folder_tree = context.active_folders.not_hidden.not_locked.pluck(:id, :parent_folder_id).inject({}) do |folders, row|
|
||||
folder_tree = context.active_folders.not_hidden.not_locked.pluck(:id, :parent_folder_id).each_with_object({}) do |row, folders|
|
||||
id, parent_folder_id = row
|
||||
folders[parent_folder_id] ||= []
|
||||
folders[parent_folder_id] << id
|
||||
folders
|
||||
end
|
||||
visible_ids = []
|
||||
dir_contents = Folder.root_folders(context).map(&:id)
|
||||
|
|
|
@ -203,9 +203,8 @@ class PageView < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def self.from_attributes(attrs, new_record = false)
|
||||
@blank_template ||= columns.inject({}) { |h, c|
|
||||
@blank_template ||= columns.each_with_object({}) { |c, h|
|
||||
h[c.name] = nil
|
||||
h
|
||||
}
|
||||
attrs = attrs.slice(*@blank_template.keys)
|
||||
shard = PageView.global_storage_namespace? ? Shard.birth : Shard.current
|
||||
|
|
|
@ -74,12 +74,11 @@ module Quizzes::LogAuditing
|
|||
# constructs submission data from events, including the parsing of flagged
|
||||
# to indicate that they are 'marked' or 'flagged'
|
||||
def build_submission_data_from_events(events)
|
||||
events.reduce({}) do |submission_data, event|
|
||||
events.each_with_object({}) do |event, submission_data|
|
||||
case event.event_type
|
||||
when Quizzes::QuizSubmissionEvent::EVT_QUESTION_FLAGGED
|
||||
submission_data["question_#{event.event_data['quiz_question_id']}_marked"] = event.event_data['flagged']
|
||||
end
|
||||
submission_data
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -56,9 +56,8 @@ class Quizzes::QuizQuestion::AnswerGroup
|
|||
|
||||
def self.generate(question)
|
||||
answers = if question[:answers].is_a? Hash
|
||||
question[:answers].reduce([]) do |arr, (key, value)|
|
||||
question[:answers].each_with_object([]) do |(key, value), arr|
|
||||
arr[key.to_i] = value
|
||||
arr
|
||||
end
|
||||
else
|
||||
question[:answers] || []
|
||||
|
|
|
@ -81,10 +81,7 @@ class Quizzes::QuizSubmissionZipper < ContentZipper
|
|||
ids = submissions.filter_map(&:submission_data).flatten.select do |submission|
|
||||
submission[:attachment_ids].present?
|
||||
end.pluck(:attachment_ids).flatten
|
||||
Attachment.where(:id => ids).inject({}) do |hash, attachment|
|
||||
hash[attachment.id] = attachment
|
||||
hash
|
||||
end
|
||||
Attachment.where(:id => ids).index_by(&:id)
|
||||
end
|
||||
|
||||
def find_submissions
|
||||
|
|
|
@ -298,7 +298,7 @@ class Role < ActiveRecord::Base
|
|||
granular_admin = context.root_account.feature_enabled?(:granular_permissions_manage_users)
|
||||
manageable = self.manageable_roles_by_user(user, context) unless granular_admin
|
||||
addable, deleteable = self.add_delete_roles_by_user(user, context) if granular_admin
|
||||
role_data.inject([]) { |roles, role|
|
||||
role_data.each_with_object([]) { |role, roles|
|
||||
is_manageable = manageable.include?(role[:base_role_name]) unless granular_admin
|
||||
is_addable = addable.include?(role[:base_role_name]) if granular_admin
|
||||
is_deleteable = deleteable.include?(role[:base_role_name]) if granular_admin
|
||||
|
@ -318,7 +318,6 @@ class Role < ActiveRecord::Base
|
|||
end
|
||||
roles << custom_role
|
||||
end
|
||||
roles
|
||||
}
|
||||
end
|
||||
|
||||
|
|
|
@ -158,9 +158,8 @@ module SpeedGrader
|
|||
res[:too_many_quiz_submissions] = too_many = assignment.too_many_qs_versions?(submissions)
|
||||
qs_versions = assignment.quiz_submission_versions(submissions, too_many)
|
||||
|
||||
enrollment_types_by_id = enrollments.inject({}) { |h, e|
|
||||
enrollment_types_by_id = enrollments.each_with_object({}) { |e, h|
|
||||
h[e.user_id] ||= e.type
|
||||
h
|
||||
}
|
||||
|
||||
if assignment.quiz
|
||||
|
|
|
@ -1830,13 +1830,12 @@ class User < ActiveRecord::Base
|
|||
accts = self.associated_accounts.where("accounts.id = ? OR accounts.root_account_id = ?", rid, rid)
|
||||
return [] if accts.blank?
|
||||
|
||||
children = accts.inject({}) do |hash, acct|
|
||||
children = accts.each_with_object({}) do |acct, hash|
|
||||
pid = acct.parent_account_id
|
||||
if pid.present?
|
||||
hash[pid] ||= []
|
||||
hash[pid] << acct
|
||||
end
|
||||
hash
|
||||
end
|
||||
|
||||
enrollment_account_ids = in_root_account
|
||||
|
|
|
@ -80,9 +80,8 @@ class WebConference < ActiveRecord::Base
|
|||
|
||||
def user_settings
|
||||
@user_settings ||=
|
||||
self.class.user_setting_fields.keys.inject({}) { |hash, key|
|
||||
hash[key] = settings[key]
|
||||
hash
|
||||
self.class.user_setting_fields.keys.index_with { |key|
|
||||
settings[key]
|
||||
}
|
||||
end
|
||||
|
||||
|
@ -142,9 +141,8 @@ class WebConference < ActiveRecord::Base
|
|||
|
||||
def default_settings
|
||||
@default_settings ||=
|
||||
self.class.user_setting_fields.inject({}) { |hash, (name, data)|
|
||||
self.class.user_setting_fields.each_with_object({}) { |(name, data), hash|
|
||||
hash[name] = data[:default] if data[:default]
|
||||
hash
|
||||
}
|
||||
end
|
||||
|
||||
|
|
|
@ -31,9 +31,8 @@ class WimbaConference < WebConference
|
|||
urls = []
|
||||
if (res = send_request('listClass', { 'filter00' => 'archive_of', 'filter00value' => wimba_id, 'attribute' => 'longname' }))
|
||||
res.delete_prefix("100 OK\n").split(/\n=END RECORD\n?/).each do |match|
|
||||
data = match.split("\n").inject({}) { |hash, line|
|
||||
data = match.split("\n").each_with_object({}) { |line, hash|
|
||||
key, hash[key.to_sym] = line.split(/=/, 2)
|
||||
hash
|
||||
}
|
||||
unless data[:longname] && data[:class_id]
|
||||
logger.error "wimba error reading archive list"
|
||||
|
|
|
@ -26,11 +26,10 @@ module ActiveModel
|
|||
# take a long time though.
|
||||
class InstructureHashReporter < HashReporter
|
||||
def to_hash
|
||||
error_hash = collection.to_hash.inject({}) do |hash, (attribute, error_message_set)|
|
||||
error_hash = collection.to_hash.each_with_object({}) do |(attribute, error_message_set), hash|
|
||||
hash[attribute] = error_message_set.map do |error_message|
|
||||
format_error_message(attribute, error_message)
|
||||
end
|
||||
hash
|
||||
end
|
||||
{ errors: error_hash }
|
||||
end
|
||||
|
|
|
@ -449,9 +449,8 @@ class ActiveRecord::Base
|
|||
end
|
||||
|
||||
def self.rank_hash(ary)
|
||||
ary.each_with_index.inject(Hash.new(ary.size + 1)) { |hash, (values, i)|
|
||||
ary.each_with_index.each_with_object(Hash.new(ary.size + 1)) { |(values, i), hash|
|
||||
Array(values).each { |value| hash[value] = i + 1 }
|
||||
hash
|
||||
}
|
||||
end
|
||||
|
||||
|
|
|
@ -68,9 +68,8 @@ module AdheresToPolicy
|
|||
session, sought_rights = parse_args(args)
|
||||
sought_rights ||= []
|
||||
sought_rights = self.class.policy.available_rights if sought_rights.empty?
|
||||
sought_rights.inject({}) do |h, r|
|
||||
h[r] = check_right?(user, session, r)
|
||||
h
|
||||
sought_rights.index_with do |r|
|
||||
check_right?(user, session, r)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@ module CanvasQuizStatistics
|
|||
def self.deep_symbolize_keys(input)
|
||||
return input unless input.is_a?(Hash)
|
||||
|
||||
input.inject({}) do |result, (key, value)|
|
||||
input.each_with_object({}) do |(key, value), result|
|
||||
new_key = key.is_a?(String) ? key.to_sym : key
|
||||
new_value = case value
|
||||
when Hash then deep_symbolize_keys(value)
|
||||
|
@ -41,7 +41,6 @@ module CanvasQuizStatistics
|
|||
end
|
||||
|
||||
result[new_key] = new_value
|
||||
result
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -40,10 +40,9 @@ module I18nTasks
|
|||
end
|
||||
|
||||
def to_ordered
|
||||
keys.sort_by(&:to_s).inject ActiveSupport::OrderedHash.new do |h, k|
|
||||
keys.sort_by(&:to_s).each_with_object ActiveSupport::OrderedHash.new do |k, h|
|
||||
v = fetch(k)
|
||||
h[k] = v.is_a?(Hash) ? v.to_ordered : v
|
||||
h
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -44,9 +44,8 @@ namespace :i18n do
|
|||
sort = ->(node) do
|
||||
case node
|
||||
when Hash
|
||||
node.keys.sort.reduce({}) do |acc, key|
|
||||
acc[key] = sort[node[key]]
|
||||
acc
|
||||
node.keys.sort.index_with do |key|
|
||||
sort[node[key]]
|
||||
end
|
||||
else
|
||||
node
|
||||
|
@ -155,9 +154,8 @@ namespace :i18n do
|
|||
|
||||
# in addition to getting the non-en stuff into each scope_file, we need to get the core
|
||||
# formats and stuff for all languages (en included) into the common scope_file
|
||||
core_translations = I18n.available_locales.inject({}) { |h1, locale|
|
||||
core_translations = I18n.available_locales.each_with_object({}) { |locale, h1|
|
||||
h1[locale.to_s] = all_translations[locale].slice(*I18nTasks::Utils::CORE_KEYS)
|
||||
h1
|
||||
}
|
||||
dump_translations.call('_core_en', { 'en' => core_translations.delete('en') })
|
||||
dump_translations.call('_core', core_translations)
|
||||
|
@ -286,9 +284,8 @@ namespace :i18n do
|
|||
puts "Exporting #{last_export[:data] ? "new/changed" : "all"} en translations..."
|
||||
current_strings = YAML.safe_load(File.read(base_filename)).flatten_keys
|
||||
new_strings = last_export[:data] ?
|
||||
current_strings.inject({}) { |h, (k, v)|
|
||||
current_strings.each_with_object({}) { |(k, v), h|
|
||||
h[k] = v unless last_export[:data][k] == v
|
||||
h
|
||||
} :
|
||||
current_strings
|
||||
File.open(export_filename, "w") { |f| f.write new_strings.expand_keys.to_yaml(line_width: -1) }
|
||||
|
|
|
@ -139,13 +139,11 @@ module IncomingMailProcessor
|
|||
end
|
||||
|
||||
def flatten_account_configs(account_configs)
|
||||
account_configs.reduce([]) do |flat_account_configs, (mailbox_protocol, mailbox_config)|
|
||||
account_configs.each_with_object([]) do |(mailbox_protocol, mailbox_config), flat_account_configs|
|
||||
flat_mailbox_configs = flatten_mailbox_overrides(mailbox_config)
|
||||
flat_mailbox_configs.each do |single_mailbox_config|
|
||||
flat_account_configs << [mailbox_protocol, single_mailbox_config]
|
||||
end
|
||||
|
||||
flat_account_configs
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -58,9 +58,8 @@ module Qti
|
|||
end
|
||||
|
||||
convert_files
|
||||
path_map = @course[:file_map].values.inject({}) { |h, v|
|
||||
path_map = @course[:file_map].values.each_with_object({}) { |v, h|
|
||||
h[v[:path_name]] = v[:migration_id]
|
||||
h
|
||||
}
|
||||
@course[:assessment_questions] = convert_questions(:file_path_map => path_map, :flavor => @flavor)
|
||||
@course[:assessments] = convert_assessments(@course[:assessment_questions][:assessment_questions])
|
||||
|
|
|
@ -71,11 +71,10 @@ module Api
|
|||
# API JSON error responses.
|
||||
class Reporter < ActiveModel::BetterErrors::HashReporter
|
||||
def to_hash
|
||||
error_list = collection.to_hash.inject([]) do |list, (attribute, error_message_set)|
|
||||
error_list = collection.to_hash.each_with_object([]) do |(attribute, error_message_set), list|
|
||||
error_message_set.each do |error_message|
|
||||
list << format_error_message(attribute, error_message)
|
||||
end
|
||||
list
|
||||
end
|
||||
{ errors: error_list }
|
||||
end
|
||||
|
|
|
@ -71,12 +71,10 @@ module Api::V1::DiscussionTopics
|
|||
opts[:context_user_count] = GuardRail.activate(:secondary) { context.enrollments.not_fake.active_or_pending_by_date_ignoring_access.count }
|
||||
end
|
||||
ActiveRecord::Associations::Preloader.new.preload(topics, [:user, :attachment, :root_topic, :context])
|
||||
topics.inject([]) do |result, topic|
|
||||
topics.each_with_object([]) do |topic, result|
|
||||
if topic.visible_for?(user)
|
||||
result << discussion_topic_api_json(topic, context || topic.context, user, session, opts, root_topics)
|
||||
end
|
||||
|
||||
result
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -39,9 +39,8 @@ module Api::V1::EnrollmentTerm
|
|||
end
|
||||
|
||||
protected def date_overrides_json(term)
|
||||
term.enrollment_dates_overrides.select { |o| o.start_at || o.end_at }.inject({}) do |json, override|
|
||||
term.enrollment_dates_overrides.select { |o| o.start_at || o.end_at }.each_with_object({}) do |override, json|
|
||||
json[override.enrollment_type] = override.attributes.slice('start_at', 'end_at')
|
||||
json
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -20,9 +20,8 @@
|
|||
|
||||
module Canvas::Plugins::Validators::AccountReportsValidator
|
||||
def self.validate(settings, _plugin_setting)
|
||||
settings.inject({}) do |result, (report_type, enabled)|
|
||||
result[report_type] = Canvas::Plugin.value_to_boolean(enabled)
|
||||
result
|
||||
settings.transform_values do |enabled|
|
||||
Canvas::Plugin.value_to_boolean(enabled)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -20,9 +20,8 @@
|
|||
|
||||
module Canvas::Plugins::Validators::I18nValidator
|
||||
def self.validate(settings, _plugin_setting)
|
||||
settings.inject({}) do |result, (i18n, enabled)|
|
||||
result[i18n] = Canvas::Plugin.value_to_boolean(enabled)
|
||||
result
|
||||
settings.transform_values do |enabled|
|
||||
Canvas::Plugin.value_to_boolean(enabled)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -29,9 +29,8 @@ module CC
|
|||
end
|
||||
|
||||
def self.whitelist
|
||||
@whitelist ||= Dir.entries(XSD_DIRECTORY).inject([]) do |memo, entry|
|
||||
@whitelist ||= Dir.entries(XSD_DIRECTORY).each_with_object([]) do |entry, memo|
|
||||
memo << entry.gsub(REGEX, '') if REGEX.match?(entry)
|
||||
memo
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -226,10 +226,9 @@ class Feature
|
|||
def default_transitions(context, orig_state)
|
||||
valid_states = [STATE_OFF, STATE_ON]
|
||||
valid_states += [STATE_DEFAULT_OFF, STATE_DEFAULT_ON] if context.is_a?(Account)
|
||||
(valid_states - [orig_state]).inject({}) do |transitions, state|
|
||||
transitions[state] = { 'locked' => ([STATE_DEFAULT_OFF, STATE_DEFAULT_ON].include?(state) && ((@applies_to == 'RootAccount' &&
|
||||
(valid_states - [orig_state]).index_with do |state|
|
||||
{ 'locked' => ([STATE_DEFAULT_OFF, STATE_DEFAULT_ON].include?(state) && ((@applies_to == 'RootAccount' &&
|
||||
context.is_a?(Account) && context.root_account? && !context.site_admin?) || @applies_to == "SiteAdmin")) }
|
||||
transitions
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -183,12 +183,11 @@ class GradebookImporter
|
|||
end
|
||||
|
||||
# cache the score on the existing object
|
||||
original_submissions_by_student = @original_submissions.inject({}) do |r, s|
|
||||
original_submissions_by_student = @original_submissions.each_with_object({}) do |s, r|
|
||||
r[s[:user_id]] ||= {}
|
||||
r[s[:user_id]][s[:assignment_id]] ||= {}
|
||||
r[s[:user_id]][s[:assignment_id]][:score] = s[:score]
|
||||
r[s[:user_id]][s[:assignment_id]][:gradeable] = s[:gradeable]
|
||||
r
|
||||
end
|
||||
|
||||
@students.each do |student|
|
||||
|
|
|
@ -88,9 +88,8 @@ module ModelCache
|
|||
end
|
||||
|
||||
def self.with_cache(lookups)
|
||||
@cache = lookups.inject({}) { |h, (k, v)|
|
||||
h[k] = prepare_lookups(v)
|
||||
h
|
||||
@cache = lookups.transform_values { |v|
|
||||
prepare_lookups(v)
|
||||
}
|
||||
yield
|
||||
ensure
|
||||
|
@ -111,9 +110,8 @@ module ModelCache
|
|||
return records if records.is_a?(Hash)
|
||||
return {} if records.empty?
|
||||
|
||||
keys[records.first.class.name].inject({}) do |h, k|
|
||||
h[k] = records.index_by(&k)
|
||||
h
|
||||
keys[records.first.class.name].index_with do |k|
|
||||
records.index_by(&k)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -91,7 +91,7 @@ module SimpleTags
|
|||
end
|
||||
|
||||
def self.normalize_tags(tags)
|
||||
tags.inject([]) { |ary, tag|
|
||||
tags.each_with_object([]) { |tag, ary|
|
||||
case tag
|
||||
when /\A((course|group)_\d+).*/
|
||||
ary << $1
|
||||
|
@ -100,7 +100,6 @@ module SimpleTags
|
|||
ary << section.course.asset_string if section
|
||||
# TODO: allow user-defined tags, e.g. #foo
|
||||
end
|
||||
ary
|
||||
}.uniq
|
||||
end
|
||||
|
||||
|
|
|
@ -96,10 +96,7 @@ class SortsAssignments
|
|||
def without_graded_submission(assignments, submissions)
|
||||
assignments ||= []
|
||||
submissions ||= []
|
||||
submissions_by_assignment = submissions.inject({}) do |memo, sub|
|
||||
memo[sub.assignment_id] = sub
|
||||
memo
|
||||
end
|
||||
submissions_by_assignment = submissions.index_by(&:assignment_id)
|
||||
assignments.select do |assignment|
|
||||
match = submissions_by_assignment[assignment.id]
|
||||
!match || match.without_graded_submission?
|
||||
|
|
|
@ -156,21 +156,20 @@ class SubmissionList
|
|||
|
||||
# Returns an array of graders with an array of assignment open structs
|
||||
def graders_for_day(day)
|
||||
hsh = self.list[day].inject({}) do |h, submission|
|
||||
hsh = self.list[day].each_with_object({}) do |submission, h|
|
||||
grader = submission[:grader]
|
||||
h[grader] ||= OpenObject.new(
|
||||
:assignments => assignments_for_grader_and_day(grader, day),
|
||||
:name => grader,
|
||||
:grader_id => submission[:grader_id]
|
||||
)
|
||||
h
|
||||
end
|
||||
hsh.values
|
||||
end
|
||||
|
||||
# Returns an array of assignments with an array of submission open structs.
|
||||
def assignments_for_grader_and_day(grader, day)
|
||||
hsh = submission_entries.find_all { |e| e[:grader] == grader and e[:graded_on] == day }.inject({}) do |h, submission|
|
||||
hsh = submission_entries.find_all { |e| e[:grader] == grader and e[:graded_on] == day }.each_with_object({}) do |submission, h|
|
||||
assignment = submission[:assignment_name]
|
||||
h[assignment] ||= OpenObject.new(
|
||||
:name => assignment,
|
||||
|
@ -179,8 +178,6 @@ class SubmissionList
|
|||
)
|
||||
|
||||
h[assignment].submissions << OpenObject.new(submission)
|
||||
|
||||
h
|
||||
end
|
||||
|
||||
hsh.each_value do |v|
|
||||
|
@ -195,16 +192,15 @@ class SubmissionList
|
|||
# all the meta data we need and no banned keys included.
|
||||
def process
|
||||
@list = self.submission_entries.sort_by { |a| [a[:graded_at] ? -a[:graded_at].to_f : CanvasSort::Last, a[:safe_grader_id], a[:assignment_id]] }
|
||||
.inject(Hashery::Dictionary.new) do |d, se|
|
||||
.each_with_object(Hashery::Dictionary.new) do |se, d|
|
||||
d[se[:graded_on]] ||= []
|
||||
d[se[:graded_on]] << se
|
||||
d
|
||||
end
|
||||
end
|
||||
|
||||
# A hash of the current grades of each submission, keyed by submission.id
|
||||
def current_grade_map
|
||||
@current_grade_map ||= self.course.submissions.not_placeholder.inject({}) do |hash, submission|
|
||||
@current_grade_map ||= self.course.submissions.not_placeholder.each_with_object({}) do |submission, hash|
|
||||
grader = if submission.grader_id.present?
|
||||
self.grader_map[submission.grader_id].try(:name)
|
||||
end
|
||||
|
@ -213,7 +209,6 @@ class SubmissionList
|
|||
hash[submission.id] = OpenObject.new(:grade => translate_grade(submission),
|
||||
:graded_at => submission.graded_at,
|
||||
:grader => grader)
|
||||
hash
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -243,7 +238,7 @@ class SubmissionList
|
|||
full_hash_list.sort_by! { |a| [a[:id], a[:updated_at]] }
|
||||
prior_submission_id, prior_grade, prior_score, prior_graded_at, prior_grader = nil
|
||||
|
||||
@filtered_submissions = full_hash_list.inject([]) do |l, h|
|
||||
@filtered_submissions = full_hash_list.each_with_object([]) do |h, l|
|
||||
# If the submission is different (not null for the first one, or just
|
||||
# different than the last one), set the previous_grade to nil (this is
|
||||
# the first version that changes a grade), set the new_grade to this
|
||||
|
@ -283,7 +278,6 @@ class SubmissionList
|
|||
prior_graded_at = h[:graded_at]
|
||||
prior_grader = h[:grader]
|
||||
prior_submission_id = h[:submission_id]
|
||||
l
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -362,10 +356,7 @@ class SubmissionList
|
|||
|
||||
# A hash of graders by their ids, for easy lookup in full_hash_list
|
||||
def grader_map
|
||||
@grader_map ||= graders.inject({}) do |h, g|
|
||||
h[g.id] = g
|
||||
h
|
||||
end
|
||||
@grader_map ||= graders.index_by(&:id)
|
||||
end
|
||||
|
||||
# A unique list of all student ids
|
||||
|
@ -381,10 +372,7 @@ class SubmissionList
|
|||
|
||||
# A hash of students by their ids, for easy lookup in full_hash_list
|
||||
def student_map
|
||||
@student_map ||= students.inject({}) do |h, s|
|
||||
h[s.id] = s
|
||||
h
|
||||
end
|
||||
@student_map ||= students.index_by(&:id)
|
||||
end
|
||||
|
||||
# A unique list of all assignment ids
|
||||
|
@ -399,9 +387,6 @@ class SubmissionList
|
|||
|
||||
# A hash of assignments by their ids, for easy lookup in full_hash_list
|
||||
def assignment_map
|
||||
@assignment_map ||= assignments.inject({}) do |h, a|
|
||||
h[a.id] = a
|
||||
h
|
||||
end
|
||||
@assignment_map ||= assignments.index_by(&:id)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -64,12 +64,9 @@ module Submittable
|
|||
end
|
||||
|
||||
# build map of user_ids to array of item ids {1 => [2,3,4], 2 => [2,4]}
|
||||
opts[:user_id].reduce({}) do |vis_hash, student_id|
|
||||
vis_hash[student_id] = begin
|
||||
ids_from_pluck = (plucked_visibilities[student_id] || []).map { |id, _, _| id }
|
||||
ids_from_pluck.concat(ids_visible_to_all).concat(ids_visible_to_sections)
|
||||
end
|
||||
vis_hash
|
||||
opts[:user_id].index_with do |student_id|
|
||||
ids_from_pluck = (plucked_visibilities[student_id] || []).map { |id, _, _| id }
|
||||
ids_from_pluck.concat(ids_visible_to_all).concat(ids_visible_to_sections)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue