Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize Database#setup_attachment_class method #17

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/paperclip/storage/database.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,11 @@ def setup_paperclip_file_model

def setup_attachment_class
instance.class.ancestors.each do |ancestor|
next unless ancestor.respond_to?(:attachment_definitions)

# Pick the top-most definition like
# Paperclip::AttachmentRegistry#definitions_for
names_for_ancestor = ancestor.attachment_definitions.keys rescue []
if names_for_ancestor.member?(name)
if ancestor.attachment_definitions.member?(name)
@attachment_class = ancestor
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we break after first definition found? Why comment says that we are looking for top-most definition? How about class A defining attachment and class B < A overriding attachment definition? In this case I think we should get definitions from class B but this code will find definition from A.

end
end
Expand Down