Module: Browserctl::State::Transport

Defined in:
lib/browserctl/state/transport.rb

Overview

Pluggable transport for moving .bctl bundles in and out of remote systems. Each transport responds to:

.scheme   String — URI scheme it handles ("file", "s3", "op", ...)
#handles?(uri)  -> Boolean
#available?     -> Boolean (e.g. CLI tool present, network reachable)
#read(uri)      -> binary String (the bundle bytes)
#write(uri, blob) -> nil; raises on failure

Transports are matched by URI scheme. A bare path with no scheme falls through to the FileTransport.

Defined Under Namespace

Classes: Base, TransportError

Class Method Summary collapse

Class Method Details

.for(uri) ⇒ Object

Raises:



32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/browserctl/state/transport.rb', line 32

def for(uri)
  parsed = parse(uri)
  match  = registry.find { |t| t.handles?(parsed) }
  raise TransportError, "no transport for #{uri.inspect}" unless match

  unless match.available?
    scheme = parsed.scheme || "file"
    raise TransportError, "transport for '#{scheme}://' is not available — install the underlying CLI"
  end

  [match, parsed]
end

.parse(uri) ⇒ Object



45
46
47
48
49
50
# File 'lib/browserctl/state/transport.rb', line 45

def parse(uri)
  uri.is_a?(URI) ? uri : URI.parse(uri.to_s)
rescue URI::InvalidURIError
  # bare path with characters URI rejects — treat as file
  URI.parse("file://#{uri}")
end

.register(transport) ⇒ Object



27
28
29
30
# File 'lib/browserctl/state/transport.rb', line 27

def register(transport)
  registry << transport
  transport
end

.registryObject



23
24
25
# File 'lib/browserctl/state/transport.rb', line 23

def registry
  @registry ||= []
end