Class: Browserctl::State::Transports::File
- Inherits:
-
Browserctl::State::Transport::Base
- Object
- Browserctl::State::Transport::Base
- Browserctl::State::Transports::File
- Defined in:
- lib/browserctl/state/transports/file.rb
Overview
Default transport — reads/writes plain files. Handles bare paths and ‘file://` URIs. Always available.
Class Method Summary collapse
Instance Method Summary collapse
Methods inherited from Browserctl::State::Transport::Base
Class Method Details
.scheme ⇒ Object
12 |
# File 'lib/browserctl/state/transports/file.rb', line 12 def self.scheme = "file" |
Instance Method Details
#local_path(parsed) ⇒ Object
27 28 29 |
# File 'lib/browserctl/state/transports/file.rb', line 27 def local_path(parsed) ::File.(parsed.path.to_s.empty? ? parsed.opaque.to_s : parsed.path) end |
#read(parsed) ⇒ Object
14 15 16 17 18 19 |
# File 'lib/browserctl/state/transports/file.rb', line 14 def read(parsed) path = local_path(parsed) raise Transport::TransportError, "file not found: #{path}" unless ::File.exist?(path) ::File.binread(path) end |
#write(parsed, blob) ⇒ Object
21 22 23 24 25 |
# File 'lib/browserctl/state/transports/file.rb', line 21 def write(parsed, blob) path = local_path(parsed) FileUtils.mkdir_p(::File.dirname(path)) ::File.open(path, "wb", 0o600) { |f| f.write(blob) } end |