Class: Opener::S3Outlet::S3Output

Inherits:
Object
  • Object
show all
Defined in:
lib/opener/s3_outlet/s3_output.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ S3Output

Returns a new instance of S3Output.



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/opener/s3_outlet/s3_output.rb', line 9

def initialize(params = {})
  @uuid     = params.fetch(:uuid) { UUIDTools::UUID.random_create }
  @text     = params.fetch(:text)
  @dir      = params.fetch(:directory, S3Outlet.dir)

  bucket = params[:bucket]
  if bucket.kind_of?(String)
    @bucket = S3Outlet.s3.buckets[bucket]
  else
    @bucket = bucket || S3Outlet.bucket
  end
end

Instance Attribute Details

#bucketObject (readonly)

attr_accessor :params, :bucket



7
8
9
# File 'lib/opener/s3_outlet/s3_output.rb', line 7

def bucket
  @bucket
end

#dirObject (readonly)

attr_accessor :params, :bucket



7
8
9
# File 'lib/opener/s3_outlet/s3_output.rb', line 7

def dir
  @dir
end

#paramsObject (readonly)

attr_accessor :params, :bucket



7
8
9
# File 'lib/opener/s3_outlet/s3_output.rb', line 7

def params
  @params
end

#textObject (readonly)

attr_accessor :params, :bucket



7
8
9
# File 'lib/opener/s3_outlet/s3_output.rb', line 7

def text
  @text
end

#uuidObject (readonly)

attr_accessor :params, :bucket



7
8
9
# File 'lib/opener/s3_outlet/s3_output.rb', line 7

def uuid
  @uuid
end

Class Method Details

.create(params = {}) ⇒ Object



39
40
41
# File 'lib/opener/s3_outlet/s3_output.rb', line 39

def self.create(params={})
  new(params).save
end

.find(uuid, dir = nil, bucket = nil) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/opener/s3_outlet/s3_output.rb', line 27

def self.find(uuid, dir=nil, bucket=nil)
  filename = construct_filename(uuid, dir)
  bucket = bucket || default_bucket

  if bucket.objects[filename].exists?
    file = bucket.objects[filename]
    return file.read
  else
    return nil
  end
end

Instance Method Details

#filenameObject



43
44
45
# File 'lib/opener/s3_outlet/s3_output.rb', line 43

def filename
  self.class.construct_filename(uuid, dir)
end

#saveObject



22
23
24
25
# File 'lib/opener/s3_outlet/s3_output.rb', line 22

def save
  object = bucket.objects[filename]
  object.write(text)
end