Module: Conduit::Storage::Aws::ClassMethods

Defined in:
lib/conduit/storage/aws.rb

Instance Method Summary collapse

Instance Method Details

#bucketObject

Bucket we want to work with

Configurable in: config/initializers/conduit.rb



51
52
53
54
55
56
57
# File 'lib/conduit/storage/aws.rb', line 51

def bucket
  @bucket ||= begin
    bucket = config[:bucket]
    connection.buckets.create(bucket) unless connection.buckets[bucket].exists?
    connection.buckets[bucket]
  end
end

#configureObject

Configure AWS::S3 if we have explicit config

TODO: This needs to be tested against AWS IAM.

I'm thinking this being a "module"
might cause issues.


28
29
30
31
32
33
# File 'lib/conduit/storage/aws.rb', line 28

def configure
  if [:aws_access_key_id, :aws_access_secret].all? { |key| config.has_key?(key) }
    AWS.config(:access_key_id => config[:aws_access_key_id],
      :secret_access_key => config[:aws_access_secret])
  end
end

#connectionObject

Primary connection object to AWS::S3

Configurable in: config/initializers/conduit.rb TODO: Update how conduit gets the credentials for s3



42
43
44
# File 'lib/conduit/storage/aws.rb', line 42

def connection
  @connection ||= AWS::S3.new
end

#delete(key) ⇒ Object

Delete a file from AWS::S3

e.g.

> Conduit::Storage.delete(‘/path/to/file’)



84
85
86
87
88
# File 'lib/conduit/storage/aws.rb', line 84

def delete(key)
  bucket.objects[key].delete
rescue AWS::S3::Errors::NoSuchKey
  nil
end

#read(key) ⇒ Object

Read a file from AWS::S3

e.g.

> Conduit::Storage.read(‘/path/to/file’)



73
74
75
76
77
# File 'lib/conduit/storage/aws.rb', line 73

def read(key)
  bucket.objects[key].read
rescue AWS::S3::Errors::NoSuchKey
  nil
end

#write(key, content) ⇒ Object

Write a file to AWS::S3

e.g.

> Conduit::Storage.write(‘/path/to/file’, ‘foo’)



64
65
66
# File 'lib/conduit/storage/aws.rb', line 64

def write(key, content)
  bucket.objects[key].write(content)
end