Created
June 11, 2020 03:26
-
-
Save mitsuhirookuno/353f5dd4660565719ef7488877f9443f 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
# frozen_string_literal: true | |
@media_website_id = 2_136 | |
def before_labels | |
registered_labels = [] | |
MediaWebsite.eager_load(media_website_labels: :label) | |
.where(id: @media_website_id).first | |
.media_website_labels.each do |media_website_label| | |
label = media_website_label.label | |
parent_label = media_website_label.label.parent | |
registered_labels.push(media_website_label_id: media_website_label.id, | |
id: label.id, | |
name: label.name, | |
parent_id: parent_label.try(:id), | |
parent_name: parent_label.try(:name) || '-') | |
end | |
registered_labels | |
end | |
def after_labels | |
media_website = MediaWebsite.eager_load(media_website_labels: :label).find(@media_website_id) | |
media_website.media_website_labels.map do |media_website_label| | |
label = media_website_label.label | |
registered_label = { | |
media_website_label_id: media_website_label.id, | |
id: label.id, | |
name: label.name, | |
parent_id: nil, | |
parent_name: '-' | |
} | |
next registered_label if label.root? | |
registered_label.merge!( | |
parent_id: label.parent.id, | |
parent_name: label.parent.name | |
) | |
end | |
end | |
def main | |
ap before_labels == after_labels | |
ap before_labels | |
ap after_labels | |
end | |
main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
root?
で確認する