Class: Opener::S3Outlet::S3Output
- Inherits:
-
Object
- Object
- Opener::S3Outlet::S3Output
- Defined in:
- lib/opener/s3_outlet/s3_output.rb
Instance Attribute Summary collapse
-
#bucket ⇒ Object
readonly
attr_accessor :params, :bucket.
-
#dir ⇒ Object
readonly
attr_accessor :params, :bucket.
-
#params ⇒ Object
readonly
attr_accessor :params, :bucket.
-
#text ⇒ Object
readonly
attr_accessor :params, :bucket.
-
#uuid ⇒ Object
readonly
attr_accessor :params, :bucket.
Class Method Summary collapse
Instance Method Summary collapse
- #filename ⇒ Object
-
#initialize(params = {}) ⇒ S3Output
constructor
A new instance of S3Output.
- #save ⇒ Object
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
#bucket ⇒ Object (readonly)
attr_accessor :params, :bucket
7 8 9 |
# File 'lib/opener/s3_outlet/s3_output.rb', line 7 def bucket @bucket end |
#dir ⇒ Object (readonly)
attr_accessor :params, :bucket
7 8 9 |
# File 'lib/opener/s3_outlet/s3_output.rb', line 7 def dir @dir end |
#params ⇒ Object (readonly)
attr_accessor :params, :bucket
7 8 9 |
# File 'lib/opener/s3_outlet/s3_output.rb', line 7 def params @params end |
#text ⇒ Object (readonly)
attr_accessor :params, :bucket
7 8 9 |
# File 'lib/opener/s3_outlet/s3_output.rb', line 7 def text @text end |
#uuid ⇒ Object (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
#filename ⇒ Object
43 44 45 |
# File 'lib/opener/s3_outlet/s3_output.rb', line 43 def filename self.class.construct_filename(uuid, dir) end |
#save ⇒ Object
22 23 24 25 |
# File 'lib/opener/s3_outlet/s3_output.rb', line 22 def save object = bucket.objects[filename] object.write(text) end |