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
definitialize()->FileSystem
Create a file system access object with no overrides.
The overrides hash, or nil if overrides are not present.
The hash maps paths to contents of the file at that path.
Returns
(Hash{String => String}, nil)
#overrides=
defoverrides=(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
defread(path,binary:false)->String,nil
Read the given file from the file system and return its contents.
Parameters
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.
Returns
(String) — if the file exists.
(nil) — if the file does not exist.
#with_overrides
defwith_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.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-09-04 UTC."],[],[],null,["# Google Cloud Platform environment queries - Class Google::Cloud::Env::FileSystem (v2.3.1)\n\nVersion latestkeyboard_arrow_down\n\n- [2.3.1 (latest)](/ruby/docs/reference/google-cloud-env/latest/Google-Cloud-Env-FileSystem)\n- [2.3.0](/ruby/docs/reference/google-cloud-env/2.3.0/Google-Cloud-Env-FileSystem)\n- [2.2.2](/ruby/docs/reference/google-cloud-env/2.2.2/Google-Cloud-Env-FileSystem) \nReference documentation and code samples for the Google Cloud Platform environment queries class Google::Cloud::Env::FileSystem.\n\nAccess to file system contents.\n\n\nThis is a simple class that reads the contents of objects in the file\nsystem, caching data so that subsequent accesses do not need to reread\nthe file system.\n\nYou can also \"mock\" the file system by providing a hash of overrides.\nIf overrides are present, actual file system access is disabled; that\nis, overrides are \"all or nothing\".\n\n\u003cbr /\u003e\n\nThis class does not provide any controls for data size. If you read a\nlarge file, its contents will stay in memory for the lifetime of the\nRuby process. \n\nInherits\n--------\n\n- Object\n\nMethods\n-------\n\n### #initialize\n\n def initialize() -\u003e FileSystem\n\nCreate a file system access object with no overrides. \n**Returns**\n\n- ([FileSystem](./Google-Cloud-Env-FileSystem)) --- a new instance of FileSystem\n\n### #overrides\n\n def overrides() -\u003e Hash{String =\u003e String}, nil\n\nThe overrides hash, or nil if overrides are not present.\nThe hash maps paths to contents of the file at that path. \n**Returns**\n\n- (Hash{String =\\\u003e String}, nil)\n\n### #overrides=\n\n def overrides=(new_overrides)\n\nSet the overrides hash. You can either provide a hash of file paths\nto content, or nil to disable overrides. If overrides are present,\nactual filesystem access is disabled; overrides are \"all or nothing\".\n\n### #read\n\n def read(path, binary: false) -\u003e String, nil\n\nRead the given file from the file system and return its contents. \n**Parameters**\n\n- **path** (String) --- The path to the file.\n- **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. \n**Returns**\n\n- (String) --- if the file exists.\n- (nil) --- if the file does not exist.\n\n### #with_overrides\n\n def with_overrides(temp_overrides)\n\nRun the given block with the overrides replaced with the given hash\n(or nil to disable overrides in the block). The original overrides\nsetting is restored at the end of the block. This is used for\ndebugging/testing/mocking. \n**Parameter**\n\n- **temp_overrides** (nil, Hash{String =\\\u003e String})"]]