Class: Neofiles::DataStore::AmazonS3

Inherits:
Object
  • Object
show all
Defined in:
app/models/neofiles/data_store/amazon_s3.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id) ⇒ AmazonS3



31
32
33
# File 'app/models/neofiles/data_store/amazon_s3.rb', line 31

def initialize(id)
  @id = id
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



29
30
31
# File 'app/models/neofiles/data_store/amazon_s3.rb', line 29

def data
  @data
end

#idObject (readonly)

Returns the value of attribute id.



29
30
31
# File 'app/models/neofiles/data_store/amazon_s3.rb', line 29

def id
  @id
end

#lengthObject (readonly)

Returns the value of attribute length.



29
30
31
# File 'app/models/neofiles/data_store/amazon_s3.rb', line 29

def length
  @length
end

#md5Object (readonly)

Returns the value of attribute md5.



29
30
31
# File 'app/models/neofiles/data_store/amazon_s3.rb', line 29

def md5
  @md5
end

Class Method Details

.bucket_nameObject



14
15
16
# File 'app/models/neofiles/data_store/amazon_s3.rb', line 14

def self.bucket_name
  Rails.application.config.neofiles.amazon_s3_bucket
end

.find(id) ⇒ Object



18
19
20
21
22
23
24
25
# File 'app/models/neofiles/data_store/amazon_s3.rb', line 18

def self.find(id)
  s3_object = new(id)
  if s3_object.data
    s3_object
  else
    raise Neofiles::DataStore::NotFoundException
  end
end

Instance Method Details

#write(data) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'app/models/neofiles/data_store/amazon_s3.rb', line 56

def write(data)
  if data.is_a? Tempfile
    data.flush
    data.rewind
    data = data.read
  end

  client.put_object(
      body: data,
      bucket: bucket_name,
      key: s3_key
  )
  @data = data
end