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
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/cataract/import_resolver.rb', line 22 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, ) else raise ImportError, "Unsupported scheme: #{uri.scheme}" end rescue Errno::ENOENT raise ImportError, "Import file not found: #{url}" rescue OpenURI::HTTPError => e raise ImportError, "HTTP error fetching import: #{url} (#{e.})" rescue SocketError => e raise ImportError, "Network error fetching import: #{url} (#{e.})" rescue StandardError => e raise ImportError, "Error fetching import: #{url} (#{e.class}: #{e.})" end |