Class: Cataract::ImportResolver::DefaultFetcher

Inherits:
Object
  • Object
show all
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

Instance Method Details

#call(url, options) ⇒ String

Fetch content from a URL

Parameters:

  • url (String)

    URL to fetch

  • options (Hash)

    Import resolution options

Returns:

  • (String)

    Fetched content

Raises:



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, options)
  uri = ImportResolver.normalize_url(url, base_path: options[:base_path], base_uri: options[:base_uri])

  case uri.scheme
  when 'file'
    # Read from local filesystem
    File.read(uri.path)
  when 'http', 'https'
    # Fetch from network
    fetch_http(uri, options)
  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.message})"
rescue SocketError => e
  raise ImportError, "Network error fetching import: #{url} (#{e.message})"
rescue StandardError => e
  raise ImportError, "Error fetching import: #{url} (#{e.class}: #{e.message})"
end