Class: Caracal::Utilities
- Inherits:
-
Object
- Object
- Caracal::Utilities
- Defined in:
- lib/caracal/utilities.rb
Class Method Summary collapse
-
.extract_options!(args) ⇒ Object
------------------------------------------------------------- Public Class Methods -------------------------------------------------------------.
-
.read_resource(location) ⇒ Object
Reads binary content from an http(s) URL or a local file path.
Class Method Details
.extract_options!(args) ⇒ Object
Public Class Methods
16 17 18 19 20 21 22 |
# File 'lib/caracal/utilities.rb', line 16 def self.(args) if args.last.is_a?(Hash) args.pop else {} end end |
.read_resource(location) ⇒ Object
Reads binary content from an http(s) URL or a local file path. Avoids Kernel#open, which no longer fetches URLs on Ruby 3+, reads in text mode on Windows, and runs a leading "|" as a shell command.
28 29 30 31 32 33 34 35 |
# File 'lib/caracal/utilities.rb', line 28 def self.read_resource(location) location = location.to_s if location =~ /\Ahttps?:\/\//i URI.open(location, 'rb', &:read) else File.binread(location) end end |