class Roda::RodaPlugins::PermissionsPolicy::Policy

Represents a permissions policy.

def append_formatted_value(s, v)

Formats nested values, quoting strings and using :self and :src verbatim.
def append_formatted_value(s, v)
  case v
  when String
    s << v.inspect << ' '
  when :self
    s << 'self '
  when :src
    s << 'src '
  else
    raise RodaError, "unsupported Permissions-Policy item value used: #{v.inspect}"
  end
end

def clear

Clear all settings, useful to remove any inherited settings.
def clear
  @opts = {}
end

def freeze

Do not allow future modifications to any settings.
def freeze
  @opts.freeze
  header_value.freeze
  super
end

def header_key

The header name to use, depends on whether report only mode has been enabled.
def header_key
  @report_only ? RodaResponseHeaders::PERMISSIONS_POLICY_REPORT_ONLY : RodaResponseHeaders::PERMISSIONS_POLICY
end

def header_value

The header value to use.
def header_value
  return @header_value if @header_value
  s = String.new
  @opts.each do |k, vs|
    s << k << "="
    if vs == :all
      s << '*, '
    else
      s << '('
      vs.each{|v| append_formatted_value(s, v)}
      s.chop! unless vs.empty?
      s << '), '
    end
  end
  s.chop!
  s.chop!
  @header_value = s
end

def initialize

def initialize
  clear
end

def initialize_copy(_)

Make object copy use copy of settings, and remove cached header value.
def initialize_copy(_)
  super
  @opts = @opts.dup
  @header_value = nil
end

def option_value(args)

The option value to store for the given args.
def option_value(args)
  if args.length == 1
    case args[0]
    when :all
      :all
    when :none
      EMPTY_ARRAY
    else
      args.freeze
    end
  else
    args.freeze
  end
end

def report_only(report=true)

default Permissions-Policy header.
Set whether the Permissions-Policy-Report-Only header instead of the
def report_only(report=true)
  @report_only = report
end

def report_only?

Whether this policy uses report only mode.
def report_only?
  !!@report_only
end

def set_header(headers)

in the policy, does not set a header.
Set the current policy in the headers hash. If no settings have been made
def set_header(headers)
  return if @opts.empty?
  headers[header_key] ||= header_value
end