class Opener::S3Outlet::S3Output

Attributes

bucket[R]

attr_accessor :params, :bucket

dir[R]

attr_accessor :params, :bucket

params[R]

attr_accessor :params, :bucket

text[R]

attr_accessor :params, :bucket

uuid[R]

attr_accessor :params, :bucket

Public Class Methods

create(params={}) click to toggle source
# File lib/opener/s3_outlet/s3_output.rb, line 37
def self.create(params={})
  new(params).save
end
find(uuid, dir=nil, bucket=nil) click to toggle source
# File lib/opener/s3_outlet/s3_output.rb, line 25
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
new(params = {}) click to toggle source
# File lib/opener/s3_outlet/s3_output.rb, line 7
def initialize(params = {})
  @uuid     = params[:uuid] || SecureRandom.hex
  @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

Private Class Methods

construct_filename(uuid, dir=nil) click to toggle source
# File lib/opener/s3_outlet/s3_output.rb, line 47
def self.construct_filename(uuid, dir=nil)
  dir = S3Outlet.dir if dir.nil? || dir.empty?
  File.join(dir, "#{uuid}.kaf")
end
default_bucket() click to toggle source
# File lib/opener/s3_outlet/s3_output.rb, line 52
def self.default_bucket
  S3Outlet.bucket
end

Public Instance Methods

filename() click to toggle source
# File lib/opener/s3_outlet/s3_output.rb, line 41
def filename
  self.class.construct_filename(uuid, dir)
end
save() click to toggle source
# File lib/opener/s3_outlet/s3_output.rb, line 20
def save
  object = bucket.objects[filename]
  object.write(text)
end