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
Instance Attribute Summary collapse
-
#bucket ⇒ Bucket
readonly
Parent bucket.
Attributes inherited from Types::Model
Instance Method Summary collapse
- #body ⇒ IO-ish
-
#body=(io) ⇒ IO
Set file body.
-
#destroy ⇒ self
Destroy file.
-
#filter(options = {}) ⇒ Array<File>
Return files matching given filter.
-
#initialize(bucket, args = {}) ⇒ self
constructor
Create a new instance.
-
#url(timeout_in_seconds = 60) ⇒ String
Create accessible URL.
Methods inherited from Types::Model
from_json, #id?, #persisted?, #reload, #save
Methods included from Utils::Memoization
#_memo, #clear_memoizations!, #memoize, #unmemoize
Methods inherited from Types::Data
from_json, #from_json, #to_json
Methods included from Utils::Lazy
Constructor Details
#initialize(bucket, args = {}) ⇒ self
Create a new instance
30 31 32 33 |
# File 'lib/miasma/models/storage/file.rb', line 30 def initialize(bucket, args={}) @bucket = bucket super bucket.api, args end |
Instance Attribute Details
#bucket ⇒ Bucket (readonly)
Returns parent bucket.
23 24 25 |
# File 'lib/miasma/models/storage/file.rb', line 23 def bucket @bucket end |
Instance Method Details
#body ⇒ IO-ish
Note:
object returned will provide #readpartial
46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/miasma/models/storage/file.rb', line 46 def body unless(attributes[:body]) begin _body = api.file_body(self) _body.stream! data[:body] = api.file_body(self) rescue HTTP::StateError data[:body] = StringIO.new(_body.to_s) end end attributes[:body] end |
#body=(io) ⇒ IO
Set file body
63 64 65 66 67 68 |
# File 'lib/miasma/models/storage/file.rb', line 63 def body=(io) unless(io.respond_to?(:readpartial)) io = StringIO.new(io) end dirty[:body] = io end |
#destroy ⇒ self
Destroy file
81 82 83 84 85 86 |
# File 'lib/miasma/models/storage/file.rb', line 81 def destroy perform_destroy data.clear dirty.clear self end |
#filter(options = {}) ⇒ Array<File>
Return files matching given filter
40 41 42 |
# File 'lib/miasma/models/storage/file.rb', line 40 def filter(={}) raise NotImplementedError end |
#url(timeout_in_seconds = 60) ⇒ String
Create accessible URL
74 75 76 |
# File 'lib/miasma/models/storage/file.rb', line 74 def url(timeout_in_seconds=60) perform_file_url(timeout_in_seconds) end |