Skip to content

Commit

Permalink
Autocorrect unsafe cops
Browse files Browse the repository at this point in the history
Special care is needed for `tag.rb` around line 190.
The autofix did not produce a valid result, I had to put extra
curly braces around that line as we want to push an object to the array.
  • Loading branch information
Splines committed Apr 15, 2024
1 parent c9c28fa commit afccc70
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 58 deletions.
5 changes: 2 additions & 3 deletions app/controllers/readers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@ def update_all
.map(&:commontator_thread)
existing_readers = Reader.where(user: current_user, thread: threads)
missing_thread_ids = threads.map(&:id) - existing_readers.pluck(:thread_id)
new_readers = []
missing_thread_ids.each do |t|
new_readers << Reader.new(thread_id: t, user: current_user)
new_readers = missing_thread_ids.map do |t|
Reader.new(thread_id: t, user: current_user)
end
Reader.import new_readers
Reader.where(user: current_user, thread: threads).touch_all
Expand Down
75 changes: 33 additions & 42 deletions app/models/manuscript.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,19 +148,16 @@ def create_or_update_chapter_items!
attrs = [:medium_id, :pdf_destination, :section_id, :sort, :page, :description, :ref_number,
:position, :quarantine]
item_details = items.pluck(*attrs).map { |i| attrs.zip(i).to_h }
contents = []
@chapters.each do |c|
contents.push(
{ medium_id: @medium.id,
pdf_destination: c["destination"],
section_id: nil,
sort: "chapter",
page: c["page"].to_i,
description: c["description"],
ref_number: c["label"],
position: nil,
quarantine: nil }
)
contents = @chapters.map do |c|
{ medium_id: @medium.id,
pdf_destination: c["destination"],
section_id: nil,
sort: "chapter",
page: c["page"].to_i,
description: c["description"],
ref_number: c["label"],
position: nil,
quarantine: nil }
end
create_or_update_items!(contents, item_details, item_destinations,
item_id_map)
Expand All @@ -176,21 +173,18 @@ def create_or_update_section_items!
attrs = [:medium_id, :pdf_destination, :section_id, :sort, :page, :description, :ref_number,
:position, :quarantine]
item_details = items.pluck(*attrs).map { |i| attrs.zip(i).to_h }
contents = []
# NOTE: that sections get a position -1 in order to place them ahead
# of all content items within themseleves in #script_items_by_position
@sections.each do |s|
contents.push(
{ medium_id: @medium.id,
pdf_destination: s["destination"],
section_id: s["mampf_section"].id,
sort: "section",
page: s["page"].to_i,
description: s["description"],
ref_number: s["label"],
position: -1,
quarantine: nil }
)
contents = @sections.map do |s|
{ medium_id: @medium.id,
pdf_destination: s["destination"],
section_id: s["mampf_section"].id,
sort: "section",
page: s["page"].to_i,
description: s["description"],
ref_number: s["label"],
position: -1,
quarantine: nil }
end
create_or_update_items!(contents, item_details, item_destinations,
item_id_map)
Expand All @@ -208,22 +202,19 @@ def create_or_update_content_items!(filter_boxes)
attrs = [:medium_id, :pdf_destination, :section_id, :sort, :page, :description, :ref_number,
:position, :hidden, :quarantine]
item_details = items.pluck(*attrs).map { |i| attrs.zip(i).to_h }
contents = []
@content.each do |c|
contents.push(
{ medium_id: @medium.id,
pdf_destination: c["destination"],
section_id: @sections.find do |s|
c["section"] == s["section"]
end ["mampf_section"]&.id,
sort: Item.internal_sort(c["sort"]),
page: c["page"].to_i,
description: c["description"],
ref_number: c["label"],
position: c["counter"],
hidden: filter_boxes[c["counter"]].third == false,
quarantine: nil }
)
contents = @content.map do |c|
{ medium_id: @medium.id,
pdf_destination: c["destination"],
section_id: @sections.find do |s|
c["section"] == s["section"]
end ["mampf_section"]&.id,
sort: Item.internal_sort(c["sort"]),
page: c["page"].to_i,
description: c["description"],
ref_number: c["label"],
position: c["counter"],
hidden: filter_boxes[c["counter"]].third == false,
quarantine: nil }
end
create_or_update_items!(contents, item_details, item_destinations,
item_id_map)
Expand Down
11 changes: 5 additions & 6 deletions app/models/medium_publisher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,12 @@ def realize_optional_stuff!
# to the medium's teachable's media_scope
def create_notifications!
@medium.teachable&.media_scope&.touch
notifications = []
@medium.teachable.media_scope.users.touch_all
@medium.teachable.media_scope.users.each do |u|
notifications << Notification.new(recipient: u,
notifiable_id: @medium.id,
notifiable_type: "Medium",
action: "create")
notifications = @medium.teachable.media_scope.users.map do |u|
Notification.new(recipient: u,
notifiable_id: @medium.id,
notifiable_type: "Medium",
action: "create")
end
Notification.import notifications
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/quiz.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def preselected_hide_solution(vertex_id, crosses)

def questions
ids = quiz_graph&.vertices&.values&.select { |v| v[:type] == "Question" }
&.map { |v| v[:id] }
&.pluck(:id)
Question.where(id: ids)
end

Expand Down
2 changes: 1 addition & 1 deletion app/models/submission.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def correction_size
end

def preceding_tutorial(user)
assignment.previous&.map { |a| a.tutorial(user) }&.compact&.first
assignment.previous&.filter_map { |a| a.tutorial(user) }&.first
end

def invited_users
Expand Down
8 changes: 3 additions & 5 deletions app/models/tag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -184,13 +184,11 @@ def self.select_by_title_except(excluded_tags)
# converts the subgraph of all tags of distance <= 2 to the given marked tag
# into a cytoscape array representing this subgraph
def self.to_cytoscape(tags, marked_tag, highlight_related_tags: true)
result = []
# add vertices
tags.each do |t|
result.push(data: t.cytoscape_vertex(marked_tag,
highlight_related_tags:
highlight_related_tags))
result = tags.map do |t|
{ data: t.cytoscape_vertex(marked_tag, highlight_related_tags: highlight_related_tags) }
end

# add edges
edges = []
tags.each do |t|
Expand Down

0 comments on commit afccc70

Please sign in to comment.