Class: Hasta::S3File

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/hasta/s3_file.rb

Overview

Hasta’s interface to the File objects returned by Fog

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(s3_file) ⇒ S3File

Returns a new instance of S3File.



26
27
28
# File 'lib/hasta/s3_file.rb', line 26

def initialize(s3_file)
  @s3_file = s3_file
end

Class Method Details

.wrap(s3_file) ⇒ Object



16
17
18
19
20
21
22
23
24
# File 'lib/hasta/s3_file.rb', line 16

def self.wrap(s3_file)
  if self === s3_file
    s3_file
  elsif s3_file.nil?
    nil
  else
    new(s3_file)
  end
end

.wrap_files(s3_files) ⇒ Object



12
13
14
# File 'lib/hasta/s3_file.rb', line 12

def self.wrap_files(s3_files)
  s3_files.map { |s3_file| wrap(s3_file) }
end

Instance Method Details

#each_lineObject



46
47
48
49
50
# File 'lib/hasta/s3_file.rb', line 46

def each_line
  return enum_for(:each_line) unless block_given?

  StringIO.new(s3_file.body).each_line { |line| yield line }
end

#fingerprintObject



34
35
36
37
38
39
40
# File 'lib/hasta/s3_file.rb', line 34

def fingerprint
  @fingerprint ||= if s3_file.respond_to? :etag
    s3_file.etag
  else
    Digest::MD5.hexdigest(body)
  end
end

#remote?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/hasta/s3_file.rb', line 42

def remote?
  !(Fog::Storage::Local::File === s3_file)
end

#s3_uriObject



30
31
32
# File 'lib/hasta/s3_file.rb', line 30

def s3_uri
  @s3_uri ||= S3URI.new(s3_file.directory.key, key)
end