Module: Fluffy

Defined in:
lib/fluffy.rb,
lib/fluffy/s3_io.rb,
lib/fluffy/s3_path.rb

Overview

RealFileUtils::File = RealFile

Defined Under Namespace

Classes: Dir, File, S3Io, S3Path

Class Method Summary collapse

Class Method Details

.cloud_runner(klass, method_name, filename, method_block = nil, &block) ⇒ Object



283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
# File 'lib/fluffy.rb', line 283

def self.cloud_runner(klass, method_name, filename, method_block=nil, &block)
  expanded_filename = File.expand_path(filename)
  if s3_path = File.s3_paths.find {|path| expanded_filename =~ /^#{path.file_path}/}
    starting_position = s3_path.file_path.length + 1
    if expanded_filename.length > starting_position
      key = expanded_filename[starting_position .. -1]
      yield(s3_path, File.join(s3_path.start_path, key).gsub(/^\W/, ''))
    elsif method_name == :directory?
      return true
    else
      raise 'You must specify a key'
    end
  else
    klass.send(method_name, filename, &method_block)
  end
end