Class: Bricolage::S3Task::Put

Inherits:
Action
  • Object
show all
Defined in:
lib/bricolage/s3datasource.rb

Instance Method Summary collapse

Constructor Details

#initialize(src, dest) ⇒ Put

Returns a new instance of Put.



149
150
151
152
# File 'lib/bricolage/s3datasource.rb', line 149

def initialize(src, dest)
  @src = src
  @dest = dest
end

Instance Method Details

#check_argumentsObject



173
174
# File 'lib/bricolage/s3datasource.rb', line 173

def check_arguments
end

#command_line(src, dest) ⇒ Object



169
170
171
# File 'lib/bricolage/s3datasource.rb', line 169

def command_line(src, dest)
  "aws s3 cp #{src} #{ds.url(dest)}"
end

#each_src_destObject



162
163
164
165
166
167
# File 'lib/bricolage/s3datasource.rb', line 162

def each_src_dest
  source_files.each do |src|
    dest = (@dest.to_s.end_with?('/') ? "#{@dest}/#{File.basename(src)}" : @dest)
    yield src, dest
  end
end

#runObject

Raises:



184
185
186
187
188
189
190
191
# File 'lib/bricolage/s3datasource.rb', line 184

def run
  raise JobFailure, "no such file: #{@src}" if source_files.empty?
  each_src_dest do |src, dest|
    ds.logger.info command_line(src, dest)
    ds.object(dest).upload_file(src)
  end
  nil
end

#single_source?Boolean

Returns:

  • (Boolean)


158
159
160
# File 'lib/bricolage/s3datasource.rb', line 158

def single_source?
  source_files.size == 1 and source_files.first == @src
end

#sourceObject



176
177
178
179
180
181
182
# File 'lib/bricolage/s3datasource.rb', line 176

def source
  buf = StringIO.new
  each_src_dest do |src, dest|
    buf.puts command_line(src, dest)
  end
  buf.string
end

#source_filesObject



154
155
156
# File 'lib/bricolage/s3datasource.rb', line 154

def source_files
  @source_files ||= Dir.glob(@src)
end