Class: Miasma::Models::Storage::File

Inherits:
Types::Model show all
Defined in:
lib/miasma/models/storage/file.rb

Overview

Abstract file

Instance Attribute Summary collapse

Attributes inherited from Types::Model

#api

Instance Method Summary collapse

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

included

Constructor Details

#initialize(bucket, args = {}) ⇒ self

Create a new instance

Parameters:



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

#bucketBucket (readonly)

Returns parent bucket.

Returns:



23
24
25
# File 'lib/miasma/models/storage/file.rb', line 23

def bucket
  @bucket
end

Instance Method Details

#bodyIO-ish

Note:

object returned will provide #readpartial

Returns:

  • (IO-ish)


46
47
48
49
50
51
# File 'lib/miasma/models/storage/file.rb', line 46

def body
  unless(attributes[:body])
    data[:body] = api.file_body(self)
  end
  attributes[:body]
end

#body=(io) ⇒ IO

Set file body

Parameters:

  • io (IO, String)

Returns:

  • (IO)


57
58
59
60
61
62
# File 'lib/miasma/models/storage/file.rb', line 57

def body=(io)
  unless(io.respond_to?(:readpartial))
    io = StringIO.new(io)
  end
  dirty[:body] = io
end

#destroyself

Destroy file

Returns:

  • (self)


75
76
77
78
79
80
# File 'lib/miasma/models/storage/file.rb', line 75

def destroy
  perform_destroy
  data.clear
  dirty.clear
  self
end

#filter(options = {}) ⇒ Array<File>

Return files matching given filter

Parameters:

  • options (Hash) (defaults to: {})

    filter options

Options Hash (options):

  • :prefix (String)

    key prefix

Returns:

Raises:

  • (NotImplementedError)


40
41
42
# File 'lib/miasma/models/storage/file.rb', line 40

def filter(options={})
  raise NotImplementedError
end

#url(timeout_in_seconds = 60) ⇒ String

Create accessible URL

Parameters:

  • timeout_in_seconds (Integer) (defaults to: 60)

    optional if private (default: 60)

Returns:

  • (String)

    URL



68
69
70
# File 'lib/miasma/models/storage/file.rb', line 68

def url(timeout_in_seconds=60)
  perform_file_url(timeout_in_seconds)
end