Class: Pipely::S3Writer

Inherits:
Object
  • Object
show all
Defined in:
lib/pipely/s3_writer.rb

Overview

Writes content from a String to an S3 path

Instance Method Summary collapse

Constructor Details

#initialize(s3_path) ⇒ S3Writer

Returns a new instance of S3Writer.



9
10
11
12
# File 'lib/pipely/s3_writer.rb', line 9

def initialize(s3_path)
  uri = URI.parse(s3_path)
  @host, @path = uri.host, uri.path.gsub(/^\//,'')
end

Instance Method Details

#directoryObject



14
15
16
17
18
# File 'lib/pipely/s3_writer.rb', line 14

def directory
  directory = storage.directories.detect{ |d| d.key == @host }

  directory or raise("Couldn't find S3 bucket '#{@host}'")
end

#write(content) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'lib/pipely/s3_writer.rb', line 20

def write(content)
  remote_file = directory.files.create({
    :key => @path,
    :body => content,
    :public => true,
  })

  remote_file.public_url
end