Class: Tumugi::Plugin::GoogleCloudStorageFileTarget
- Inherits:
-
FileSystemTarget
- Object
- FileSystemTarget
- Tumugi::Plugin::GoogleCloudStorageFileTarget
- Defined in:
- lib/tumugi/plugin/target/google_cloud_storage_file.rb
Instance Attribute Summary collapse
-
#bucket ⇒ Object
readonly
Returns the value of attribute bucket.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #fs ⇒ Object
-
#initialize(bucket:, key:, fs: nil) ⇒ GoogleCloudStorageFileTarget
constructor
A new instance of GoogleCloudStorageFileTarget.
- #open(mode = "r", &block) ⇒ Object
- #to_s ⇒ Object
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
#bucket ⇒ Object (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 |
#key ⇒ Object (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 |
#path ⇒ Object (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
#fs ⇒ Object
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_s ⇒ Object
36 37 38 |
# File 'lib/tumugi/plugin/target/google_cloud_storage_file.rb', line 36 def to_s path end |