Reference documentation and code samples for the Google Cloud Platform environment queries class Google::Cloud::Env::FileSystem.
Access to file system contents.
This is a simple class that reads the contents of objects in the file system, caching data so that subsequent accesses do not need to reread the file system.
You can also "mock" the file system by providing a hash of overrides. If overrides are present, actual file system access is disabled; that is, overrides are "all or nothing".
This class does not provide any controls for data size. If you read a large file, its contents will stay in memory for the lifetime of the Ruby process.
Inherits
- Object
Methods
#initialize
def initialize() -> FileSystem
Create a file system access object with no overrides.
- (FileSystem) — a new instance of FileSystem
#overrides
def overrides() -> Hash{String => String}, nil
The overrides hash, or nil if overrides are not present. The hash maps paths to contents of the file at that path.
- (Hash{String => String}, nil)
#overrides=
def overrides=(new_overrides)
Set the overrides hash. You can either provide a hash of file paths to content, or nil to disable overrides. If overrides are present, actual filesystem access is disabled; overrides are "all or nothing".
#read
def read(path, binary: false) -> String, nil
Read the given file from the file system and return its contents.
- path (String) — The path to the file.
- binary (boolean) (defaults to: false) — Whether to read in binary mode. Defaults to false. This must be consistent across multiple requests for the same path; if it is not, an error will be raised.
- (String) — if the file exists.
- (nil) — if the file does not exist.
#with_overrides
def with_overrides(temp_overrides)
Run the given block with the overrides replaced with the given hash (or nil to disable overrides in the block). The original overrides setting is restored at the end of the block. This is used for debugging/testing/mocking.
- temp_overrides (nil, Hash{String => String})