Class: Middleman::S3Sync::BrowserCachePolicy

Inherits:
Object
  • Object
show all
Defined in:
lib/middleman/s3_sync/caching_policy.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ BrowserCachePolicy

Returns a new instance of BrowserCachePolicy.



27
28
29
# File 'lib/middleman/s3_sync/caching_policy.rb', line 27

def initialize(options = {})
  @policies = Map.from_hash(options)
end

Instance Attribute Details

#policiesObject

Returns the value of attribute policies.



25
26
27
# File 'lib/middleman/s3_sync/caching_policy.rb', line 25

def policies
  @policies
end

Instance Method Details

#cache_controlObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/middleman/s3_sync/caching_policy.rb', line 31

def cache_control
  policy = []
  policy << "max-age=#{policies.max_age}" if policies.has_key?(:max_age)
  policy << "s-maxage=#{policies.s_maxage}" if policies.has_key?(:s_maxage)
  policy << "public" if policies.fetch(:public, false)
  policy << "private" if policies.fetch(:private, false)
  policy << "no-cache" if policies.fetch(:no_cache, false)
  policy << "no-store" if policies.fetch(:no_store, false)
  policy << "must-revalidate" if policies.fetch(:must_revalidate, false)
  policy << "proxy-revalidate" if policies.fetch(:proxy_revalidate, false)
  if policy.empty?
    nil
  else
    policy.join(", ")
  end
end

#expiresObject



52
53
54
55
56
# File 'lib/middleman/s3_sync/caching_policy.rb', line 52

def expires
  if expiration = policies.fetch(:expires, nil)
    CGI.rfc1123_date(expiration)
  end
end

#to_sObject



48
49
50
# File 'lib/middleman/s3_sync/caching_policy.rb', line 48

def to_s
  cache_control
end