module CHECKING::YOU::SweetSweet♡Magic
Find-by-content file matching à la `libmagic`. Class-level components.
Constants
- WILD_IO
Main find-by-content matching code, externalized for reusability. TODO: Find and fix all the bugs in this by running a test suite. TODO: Profile this to reduce allocations.
Public Instance Methods
from_content(unknown_io)
click to toggle source
Apply the find-by-content matcher on various types of input. For example, paths representing files need to be opened for reading.
# File lib/checking-you-out/sweet_sweet_love_magic.rb, line 209 def from_content(unknown_io) case unknown_io when IO, StringIO # `IO` is the parent class of `File`, among others. # Assume for now that we should not `#close` an IO we were directly given. unknown_io.advise(:sequential) return WILD_IO.call(unknown_io) when String, Pathname # File::open takes a path, but IO::open only takes a file descriptor. # The File handle will be closed as soon as we exit the block scope. File.open(unknown_io, mode: File::Constants::RDONLY|File::Constants::BINARY) do |wild_io| wild_io.advise(:sequential) return WILD_IO.call(wild_io) end else nil end end
magic_without_tears()
click to toggle source
# File lib/checking-you-out/sweet_sweet_love_magic.rb, line 135 def magic_without_tears @magic_without_tears ||= ::CHECKING::YOU::MagicWithoutTears.new end