Class: Awshark::S3::Artifact

Inherits:
Object
  • Object
show all
Defined in:
lib/awshark/s3/artifact.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key) ⇒ Artifact

Returns a new instance of Artifact.



8
9
10
# File 'lib/awshark/s3/artifact.rb', line 8

def initialize(key)
  @key = key
end

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key.



6
7
8
# File 'lib/awshark/s3/artifact.rb', line 6

def key
  @key
end

Instance Method Details

#basenameObject



33
34
35
# File 'lib/awshark/s3/artifact.rb', line 33

def basename
  ::File.basename(key)
end

#cache_controlObject



12
13
14
15
16
# File 'lib/awshark/s3/artifact.rb', line 12

def cache_control
  return "public, max-age=#{1.year.to_i}, s-maxage=#{1.year.to_i}" if fingerprint?

  'public, max-age=0, s-maxage=120, must-revalidate'
end

#content_typeObject



24
25
26
27
28
29
30
31
# File 'lib/awshark/s3/artifact.rb', line 24

def content_type
  mime = MiniMime.lookup_by_filename(basename)
  if mime
    mime.content_type
  else
    'application/octet-stream'
  end
end

#fingerprint?Boolean

Returns:

  • (Boolean)


18
19
20
21
22
# File 'lib/awshark/s3/artifact.rb', line 18

def fingerprint?
  return false if key.blank?

  basename.match(/\.([0-9a-f]{20}|[0-9a-f]{32})\./).present?
end