Class: Cataract::ImportResolver::DefaultFetcher
- Inherits:
-
Object
- Object
- Cataract::ImportResolver::DefaultFetcher
- Defined in:
- lib/cataract/import_resolver.rb
Overview
Default fetcher implementation using File I/O and Net::HTTP Can be replaced with custom fetchers for different environments (e.g., browser, caching)
Instance Method Summary collapse
-
#call(url, options) ⇒ String
Fetch content from a URL.
Instance Method Details
#call(url, options) ⇒ String
Fetch content from a URL
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/cataract/import_resolver.rb', line 21 def call(url, ) uri = ImportResolver.normalize_url(url, base_path: [:base_path], base_uri: [:base_uri]) case uri.scheme when 'file' # Read from local filesystem File.read(uri.path) when 'http', 'https' # Fetch from network fetch_http(uri, , url) else raise ImportError, "Unsupported scheme: #{uri.scheme}" end rescue Errno::ENOENT raise ImportError, "Import file not found: #{url}" rescue ImportError raise # already specific; re-wrapping nests it inside a vaguer message rescue StandardError => e raise ImportError, "Error fetching import: #{url} (#{e.class}: #{e.})" end |