Class: Bindan::Provider::Storage
- Inherits:
-
Object
- Object
- Bindan::Provider::Storage
- Defined in:
- lib/bindan/providers/storage.rb
Defined Under Namespace
Classes: FileNotExist
Instance Attribute Summary collapse
-
#project_id ⇒ Object
readonly
Returns the value of attribute project_id.
-
#separator ⇒ Object
readonly
Returns the value of attribute separator.
Instance Method Summary collapse
- #[](file) ⇒ String
-
#bucket ⇒ String
decorated bucket name.
-
#initialize(bucket, raise_error: nil, separator: "-", sdk: ::Google::Cloud::Storage, **kwargs) ⇒ Storage
constructor
A new instance of Storage.
- #prepare_options(options) ⇒ Hash
Constructor Details
#initialize(bucket, raise_error: nil, separator: "-", sdk: ::Google::Cloud::Storage, **kwargs) ⇒ Storage
Returns a new instance of Storage.
40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/bindan/providers/storage.rb', line 40 def initialize(bucket, raise_error: nil, separator: "-", sdk: ::Google::Cloud::Storage, **kwargs) = {} @bucket = bucket [:raise_error] = raise_error @separator = separator @project_id = kwargs[:project_id] = (kwargs) @_storage = sdk.new(**) end |
Instance Attribute Details
#project_id ⇒ Object (readonly)
Returns the value of attribute project_id.
52 53 54 |
# File 'lib/bindan/providers/storage.rb', line 52 def project_id @project_id end |
#separator ⇒ Object (readonly)
Returns the value of attribute separator.
52 53 54 |
# File 'lib/bindan/providers/storage.rb', line 52 def separator @separator end |
Instance Method Details
#[](file) ⇒ String
82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/bindan/providers/storage.rb', line 82 def [](file) remote = @_storage.bucket(bucket).file(file) if remote Tempfile.open { |t| remote.download(t.path) t.read.chomp } elsif [:raise_error] raise FileNotExist.new file end end |
#bucket ⇒ String
decorated bucket name
73 74 75 |
# File 'lib/bindan/providers/storage.rb', line 73 def bucket [@project_id, @bucket].join(@separator) end |
#prepare_options(options) ⇒ Hash
58 59 60 61 62 63 64 65 66 |
# File 'lib/bindan/providers/storage.rb', line 58 def () if ENV["STORAGE_EMULATOR_HOST"] u = URI(ENV["STORAGE_EMULATOR_HOST"].to_s) u.path = "/" if u.path.to_s.size == 0 [:endpoint] = u.to_s end end |