Class: Miasma::Models::Storage::File
- Inherits:
-
Types::Model
- Object
- Types::Data
- Types::Model
- Miasma::Models::Storage::File
- Defined in:
- lib/miasma/models/storage/file.rb
Overview
Abstract file
Defined Under Namespace
Classes: Streamable
Instance Attribute Summary (collapse)
-
- (Miasma::Types::Api) api
inherited
from Types::Model
readonly
Underlying service API.
-
- (Bucket) bucket
readonly
Parent bucket.
Instance Method Summary (collapse)
- - (IO-ish) body
-
- (IO) body=(io)
Set file body.
-
- (self) destroy
Destroy file.
-
- (Array<File>) filter(options = {})
Return files matching given filter.
-
- (self) initialize(bucket, args = {})
constructor
Create a new instance.
-
- (String) url(timeout_in_seconds = 60)
Create accessible URL.
Constructor Details
- (self) initialize(bucket, args = {})
Create a new instance
66 67 68 69 |
# File 'lib/miasma/models/storage/file.rb', line 66 def initialize(bucket, args={}) @bucket = bucket super bucket.api, args end |
Instance Attribute Details
- (Miasma::Types::Api) api (readonly) Originally defined in class Types::Model
Returns underlying service API
- (Bucket) bucket (readonly)
Returns parent bucket
59 60 61 |
# File 'lib/miasma/models/storage/file.rb', line 59 def bucket @bucket end |
Instance Method Details
- (IO-ish) body
Note:
object returned will provide #readpartial
82 83 84 85 86 87 |
# File 'lib/miasma/models/storage/file.rb', line 82 def body unless(attributes[:body]) data[:body] = api.file_body(self) end attributes[:body] end |
- (IO) body=(io)
Set file body
93 94 95 96 97 98 |
# File 'lib/miasma/models/storage/file.rb', line 93 def body=(io) unless(io.respond_to?(:readpartial)) io = StringIO.new(io) end dirty[:body] = io end |
- (self) destroy
Destroy file
111 112 113 114 115 116 |
# File 'lib/miasma/models/storage/file.rb', line 111 def destroy perform_destroy data.clear dirty.clear self end |
- (Array<File>) filter(options = {})
Return files matching given filter
76 77 78 |
# File 'lib/miasma/models/storage/file.rb', line 76 def filter(={}) raise NotImplementedError end |
- (String) url(timeout_in_seconds = 60)
Create accessible URL
104 105 106 |
# File 'lib/miasma/models/storage/file.rb', line 104 def url(timeout_in_seconds=60) perform_file_url(timeout_in_seconds) end |