class Roda::RodaPlugins::PermissionsPolicy::Policy
Represents a permissions policy.
def append_formatted_value(s, v)
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
def clear @opts = {} end
def freeze
def freeze @opts.freeze header_value.freeze super end
def header_key
def header_key @report_only ? RodaResponseHeaders::PERMISSIONS_POLICY_REPORT_ONLY : RodaResponseHeaders::PERMISSIONS_POLICY end
def header_value
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(_)
def initialize_copy(_) super @opts = @opts.dup @header_value = nil end
def option_value(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)
Set whether the Permissions-Policy-Report-Only header instead of the
def report_only(report=true) @report_only = report end
def report_only?
def report_only? !!@report_only end
def set_header(headers)
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