class Roda::RodaPlugins::PermissionsPolicy::Policy
Represents a permissions policy.
Public Class Methods
Public Instance Methods
Source
# File lib/roda/plugins/permissions_policy.rb, line 181 def clear @opts = {} end
Clear all settings, useful to remove any inherited settings.
Source
# File lib/roda/plugins/permissions_policy.rb, line 186 def freeze @opts.freeze header_value.freeze super end
Do not allow future modifications to any settings.
Calls superclass method
Source
# File lib/roda/plugins/permissions_policy.rb, line 193 def header_key @report_only ? RodaResponseHeaders::PERMISSIONS_POLICY_REPORT_ONLY : RodaResponseHeaders::PERMISSIONS_POLICY end
The header name to use, depends on whether report only mode has been enabled.
Source
# File lib/roda/plugins/permissions_policy.rb, line 198 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
The header value to use.
Source
# File lib/roda/plugins/permissions_policy.rb, line 221 def report_only(report=true) @report_only = report end
Set whether the Permissions-Policy-Report-Only header instead of the default Permissions-Policy header.
Source
# File lib/roda/plugins/permissions_policy.rb, line 226 def report_only? !!@report_only end
Whether this policy uses report only mode.
Source
# File lib/roda/plugins/permissions_policy.rb, line 232 def set_header(headers) return if @opts.empty? headers[header_key] ||= header_value end
Set the current policy in the headers hash. If no settings have been made in the policy, does not set a header.
Private Instance Methods
Source
# File lib/roda/plugins/permissions_policy.rb, line 240 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
Formats nested values, quoting strings and using :self and :src verbatim.
Source
# File lib/roda/plugins/permissions_policy.rb, line 254 def initialize_copy(_) super @opts = @opts.dup @header_value = nil end
Make object copy use copy of settings, and remove cached header value.
Calls superclass method
Source
# File lib/roda/plugins/permissions_policy.rb, line 261 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
The option value to store for the given args.