class GoogleCloudStorage
Public Class Methods
new(project_name, app_name, credentials_path)
click to toggle source
@param [string] project_name @param [string] app_name @param [string] credentials_path
# File lib/infrastructure/google_cloud_platform/google_cloud_storage.rb, line 6 def initialize(project_name, app_name, credentials_path) @project_name = project_name @app_name = app_name @credentials = credentials_path @storage = Gcloud.storage @project_name, @credentials @bucket = get_bucket end
Public Instance Methods
copy_file(existing_filepath, new_filepath)
click to toggle source
@param [string] existing_filepath @param [string] new_filepath @return [File]
# File lib/infrastructure/google_cloud_platform/google_cloud_storage.rb, line 49 def copy_file(existing_filepath, new_filepath) existing_file = @bucket.find_file existing_filepath puts "Copying #{existing_filepath} to #{new_filepath} on Google Cloud Storage" existing_file.copy new_filepath end
get_bucket_name()
click to toggle source
# File lib/infrastructure/google_cloud_platform/google_cloud_storage.rb, line 15 def get_bucket_name "#{@project_name}_#{@app_name}" end
put_file(filepath, storage_path)
click to toggle source
@param [string] filepath @param [string] storage_path @return [File]
# File lib/infrastructure/google_cloud_platform/google_cloud_storage.rb, line 40 def put_file(filepath, storage_path) puts "Putting #{filepath} to #{storage_path} on Google Cloud Storage" @bucket.create_file filepath, storage_path end
Private Instance Methods
get_bucket()
click to toggle source
@return [Bucket]
# File lib/infrastructure/google_cloud_platform/google_cloud_storage.rb, line 21 def get_bucket buckets = @storage.buckets bucket_names = [] buckets.each do |bucket| if bucket.name == get_bucket_name return bucket end bucket_names.push(bucket.name) end puts bucket_names @storage.create_bucket get_bucket_name, retries: 3 end