Class: RubyRemoteConfig::GcpStorageRepository
- Inherits:
-
Object
- Object
- RubyRemoteConfig::GcpStorageRepository
- Includes:
- Repository
- Defined in:
- lib/gcp_storage_repository.rb
Instance Attribute Summary collapse
-
#bucket_name ⇒ Object
readonly
Returns the value of attribute bucket_name.
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#object_name ⇒ Object
readonly
Returns the value of attribute object_name.
Attributes included from Repository
Instance Method Summary collapse
-
#initialize(name:, bucket_name:, object_name:) ⇒ GcpStorageRepository
constructor
A new instance of GcpStorageRepository.
-
#refresh ⇒ Object
Refresh reads the YAML file from the GCS bucket, unmarshal it into the data map.
Methods included from Repository
Constructor Details
#initialize(name:, bucket_name:, object_name:) ⇒ GcpStorageRepository
Returns a new instance of GcpStorageRepository.
14 15 16 17 18 19 |
# File 'lib/gcp_storage_repository.rb', line 14 def initialize(name:, bucket_name:, object_name:) super(name: name) @bucket_name = bucket_name @object_name = object_name @client = nil end |
Instance Attribute Details
#bucket_name ⇒ Object (readonly)
Returns the value of attribute bucket_name.
12 13 14 |
# File 'lib/gcp_storage_repository.rb', line 12 def bucket_name @bucket_name end |
#client ⇒ Object (readonly)
Returns the value of attribute client.
12 13 14 |
# File 'lib/gcp_storage_repository.rb', line 12 def client @client end |
#object_name ⇒ Object (readonly)
Returns the value of attribute object_name.
12 13 14 |
# File 'lib/gcp_storage_repository.rb', line 12 def object_name @object_name end |
Instance Method Details
#refresh ⇒ Object
Refresh reads the YAML file from the GCS bucket, unmarshal it into the data map.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/gcp_storage_repository.rb', line 22 def refresh @lock.synchronize do # If the GCS client does not exist, create it. if @client.nil? @client = Google::Cloud::Storage.new() end # Open the YAML file from the GCS bucket. bucket = @client.bucket(@bucket_name) file = bucket.file(@object_name) file_content = file.download # Unmarshal the YAML data into the data map. @data = YAML.safe_load(file_content) @raw_data = file_content end rescue StandardError => e raise "Error refreshing configuration data: #{e.}" end |