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

Add explanation of MimeType.for's handling of argument types #68

Merged
merged 1 commit into from
Apr 27, 2022

Conversation

elebow
Copy link
Contributor

@elebow elebow commented Mar 18, 2022

Adds an explicit statement that Marcel's primary interface is Marcel::MimeType.for, and that the first argument is handled differently depending on whether it is a Pathname. This information was previously present in the Readme, but only indirectly through the code examples.

README.md Outdated
@@ -2,6 +2,8 @@

Marcel attempts to choose the most appropriate content type for a given file by looking at the binary data, the filename, and any declared type (perhaps passed as a request header):

The primary interface is the method `Marcel::MimeType.for`. If the first argument is a `Pathname`, Marcel will evaluate the contents of the specified file. Any other type is assumed to be an `IO`, and Marcel will evaluate its contents.
Copy link
Member

Choose a reason for hiding this comment

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

I don't think this really fits the tone of the documentation. Let's make the following changes instead:

  • Reword the starting sentences to this: "Marcel attempts to choose the most appropriate content type for a given file by looking at the binary data, the filename, and any declared type (perhaps passed as a request header). It's used like this:"
  • Add an example above the motivation section with something like "Marcel expects either a Pathname or IO object to read content type data from: Marcel::MimeType.for Object.new # => "application/octet-stream""
  • Document the Marcel::MimeType.for method.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the comments.

👍 to documenting Marcel::MimeType.for.

I'm not sure I understand the value of the second bullet point. As a new user, the question I had that motivated this PR was: I want to know all of the ways to use this gem so I can select the one that fits my needs. It turns out that the gem offers exactly one public interface, but that wasn't spelled out explicitly in the README. I instead propose a sentence at the end of the first section doing so.

@elebow elebow force-pushed the readme-explain-for-pathname-argument branch from 77e7157 to 94f7d9c Compare April 22, 2022 20:17
lib/marcel/mime_type.rb Outdated Show resolved Hide resolved
lib/marcel/mime_type.rb Outdated Show resolved Hide resolved
lib/marcel/mime_type.rb Outdated Show resolved Hide resolved
lib/marcel/mime_type.rb Outdated Show resolved Hide resolved
README.md Outdated
@@ -43,6 +43,8 @@ Marcel::MimeType.for Pathname.new("example.png"), name: "example.ai"
# As "application/illustrator" is not a more specific type of "image/png", the filename is ignored
```

`Marcel::MimeType.for` is Marcel's only public interface.
Copy link
Member

Choose a reason for hiding this comment

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

Marcel::MimeType.extend and Marcel::Magic are all public API as well, so that sentence isn't right. The gist is that Marcel::MimeType.for is how the gem is used to identify mimes, so we can compromise on that. Let's amend the the beginning sentence to: "Marcel attempts to choose the most appropriate content type for a given file by looking at the binary data, the filename, and any declared type (perhaps passed as a request header). This is done via the Marcel::MimeType.for method, and is used like this:"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good to me. Changes pushed.

@elebow elebow force-pushed the readme-explain-for-pathname-argument branch from d911502 to 9160594 Compare April 26, 2022 20:55
Copy link
Member

@gmcgibbon gmcgibbon left a comment

Choose a reason for hiding this comment

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

Thanks! Please squash your commits into one and I'll merge.

on-behalf-of: @Cofense <oss@cofense.com>
@elebow elebow force-pushed the readme-explain-for-pathname-argument branch from 1635990 to d2b6e39 Compare April 27, 2022 16:27
@elebow
Copy link
Contributor Author

elebow commented Apr 27, 2022

Squashed.

@gmcgibbon gmcgibbon merged commit 64fe97d into rails:main Apr 27, 2022
@elebow elebow deleted the readme-explain-for-pathname-argument branch January 26, 2023 17:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants