Class: Tumugi::Plugin::GoogleCloudStorageFileTarget

Inherits:
FileSystemTarget
  • Object
show all
Defined in:
lib/tumugi/plugin/target/google_cloud_storage_file.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(bucket:, key:, fs: nil) ⇒ GoogleCloudStorageFileTarget

Returns a new instance of GoogleCloudStorageFileTarget.



15
16
17
18
19
20
# File 'lib/tumugi/plugin/target/google_cloud_storage_file.rb', line 15

def initialize(bucket:, key:, fs: nil)
  @bucket = bucket
  @key = key
  @path = "gs://#{File.join(bucket, key)}"
  @fs = fs unless fs.nil?
end

Instance Attribute Details

#bucketObject (readonly)

Returns the value of attribute bucket.



13
14
15
# File 'lib/tumugi/plugin/target/google_cloud_storage_file.rb', line 13

def bucket
  @bucket
end

#keyObject (readonly)

Returns the value of attribute key.



13
14
15
# File 'lib/tumugi/plugin/target/google_cloud_storage_file.rb', line 13

def key
  @key
end

#pathObject (readonly)

Returns the value of attribute path.



13
14
15
# File 'lib/tumugi/plugin/target/google_cloud_storage_file.rb', line 13

def path
  @path
end

Instance Method Details

#fsObject



22
23
24
# File 'lib/tumugi/plugin/target/google_cloud_storage_file.rb', line 22

def fs
  @fs ||= Tumugi::Plugin::GoogleCloudStorage::FileSystem.new(Tumugi.config.section('google_cloud_storage'))
end

#open(mode = "r", &block) ⇒ Object



26
27
28
29
30
31
32
33
34
# File 'lib/tumugi/plugin/target/google_cloud_storage_file.rb', line 26

def open(mode="r", &block)
  if mode.include? 'r'
    fs.download(path, mode: mode, &block)
  elsif mode.include? 'w'
    Tumugi::Plugin::GoogleCloudStorage::AtomicFile.new(path, fs).open(&block)
  else
    raise Tumugi::TumugiError.new('Invalid mode: #{mode}')
  end
end

#to_sObject



36
37
38
# File 'lib/tumugi/plugin/target/google_cloud_storage_file.rb', line 36

def to_s
  path
end