-
Notifications
You must be signed in to change notification settings - Fork 73
Fix #144. Add support for Tempfile / ActiveStorage #186
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
base: master
Are you sure you want to change the base?
Conversation
lib/inline_svg/io_resource.rb
Outdated
def self.default_for(object) | ||
case object | ||
when StringIO then '' | ||
when IO then 1 | ||
end | ||
object.is_a?(IO) || object.is_a?(StringIO) || object.is_a?(Tempfile) | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hello, I understand that default_for
appears not to be used by this library and it is not even tested, but is there a reason to remove it entirely?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I want to remind you that the main reason is that it is not used in the library and it makes no sense to have code that is not used, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it makes no sense to have code that is not used, right?
I completely agree. However, it’s important to consider possible breaking changes to the public API. That doesn’t seem to be the case here, and since the master branch already includes breaking changes, now is a good time to remove it. Keeping the commit isolated is also better in case it needs a revert
Additionally, the commit message doesn’t clarify the reason for the removal, so it appears to be related to this new functionality.
I’ve separated the removal into its own commit with a clear message and investigated why the code is unnecessary or was never needed, so this PR can just address the ActiveStorage support. Ref: #187.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great, I think it's a great option. As soon as the other PR is up, I'll update this one!
This method, introduced in the 4b13f77 commit along with the IOResource class, is not utilized in either production or test code. To the best of my understanding, this discrepancy may be attributed to a copy-and-paste error. Ref: jamesmartin#186
@javierav can you please rebase and add an entry in the changelog? |
2f7df15
to
f5d6b15
Compare
Thanks. I'm performing some tests. Can you please clarify how to use this feature? Let's say that I have class User < ApplicationRecord
has_one_attached :avatar
end Rails 8.0 I was expecting <%= inline_svg_tag(user.avatar) %> but I'm getting
(which is the same issue on master and the same issue we see at #144) edit: I guess that the helper in the opening post is mandatory, and this PR only supports Tempfile (which is a requirement for ActiveStorage support), so if you don't have the helper something like <%= user.avatar.open { |file| inline_svg_tag file } %> |
If we want to use this gem with an SVG stored in Active Storage, we have to temporarily download the file and then use it with gem helper
The problem is that Active Storage uses a temporary file with the
Tempfile
class that usesDelegateClass
overFile
, so technically it behaves like aFile
but does not inherit from it, so it could not be used with this gem.This PR fixes that issue by providing support for
Tempfile
.