class Rack::AcornCache::CacheControlHeader

Attributes

max_age[RW]
max_fresh[RW]
max_stale[RW]
max_stale?[RW]
must_revalidate[RW]
must_revalidate?[RW]
no_cache[RW]
no_cache?[RW]
no_store[RW]
no_store?[RW]
private[RW]
private?[RW]
s_maxage[RW]

Public Class Methods

new(header_string = "") click to toggle source
# File lib/acorn_cache/cache_control_header.rb, line 8
def initialize(header_string = "")
  return unless header_string && !header_string.empty?
  set_directive_instance_variables!(header_string)
end

Public Instance Methods

to_s() click to toggle source
# File lib/acorn_cache/cache_control_header.rb, line 19
def to_s
  instance_variables.map do |ivar|
    directive = ivar.to_s.sub("@", "").sub("_", "-")
    value = instance_variable_get(ivar)
    next directive if value == true
    next unless value
    "#{directive}=#{value}"
  end.compact.sort.join(", ")
end

Private Instance Methods

directive_value(value) click to toggle source
# File lib/acorn_cache/cache_control_header.rb, line 42
def directive_value(value)
  return value.to_i if value =~ /^[0-9]+$/
  return true if value.nil?
  value
end
set_directive_instance_variables!(header_string) click to toggle source
# File lib/acorn_cache/cache_control_header.rb, line 31
def set_directive_instance_variables!(header_string)
  header_string.gsub(/\s+/, "").split(",").each do |directive, result|
    k, v = directive.split("=")
    instance_variable_set(variable_symbol(k), directive_value(v))
  end
end
variable_symbol(directive) click to toggle source
# File lib/acorn_cache/cache_control_header.rb, line 38
def variable_symbol(directive)
  "@#{directive.gsub("-", "_")}".to_sym
end