Class: StaticSync::Meta

Inherits:
Object
  • Object
show all
Defined in:
lib/static_sync/meta.rb,
lib/static_sync/meta/caching.rb,
lib/static_sync/meta/compression.rb

Defined Under Namespace

Classes: Caching, Compression

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Meta

Returns a new instance of Meta.



10
11
12
13
14
# File 'lib/static_sync/meta.rb', line 10

def initialize(config)
  @config      = config
  @compression = Compression.new(@config)
  @caching     = Caching.new(@config)
end

Instance Method Details

#for(file) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/static_sync/meta.rb', line 16

def for(file)
  meta = {
    :key                => file,
    :body               => File.new(file),
    :public             => true,
    :storage_class      => 'REDUCED_REDUNDANCY'
  }

  mime = MIME::Types::of(file).first

  if mime
    meta.merge!(
      :content_type => MIME::Type.simplified(mime)
    )
    meta.merge!(@compression.for(file, mime))
    meta.merge!(@caching.for(file, mime))
  end

  body = meta[:body].read

  meta.merge!(
    :etag        => Digest::MD5.hexdigest(body),   # A local version of the etag expected after upload.
    :content_md5 => Digest::MD5.base64digest(body) # Enable checksum validation during uploads.
  )
end