Represents a permissions policy.
Methods
Public Class
Public Instance
Public Class methods
new()
[show source]
# File lib/roda/plugins/permissions_policy.rb 178 def initialize 179 clear 180 end
Public Instance methods
clear()
Clear all settings, useful to remove any inherited settings.
[show source]
# File lib/roda/plugins/permissions_policy.rb 183 def clear 184 @opts = {} 185 @report_only = nil 186 @header_value = nil 187 end
freeze()
Do not allow future modifications to any settings.
[show source]
# File lib/roda/plugins/permissions_policy.rb 190 def freeze 191 @opts.freeze 192 header_value.freeze 193 super 194 end
header_key()
The header name to use, depends on whether report only mode has been enabled.
[show source]
# File lib/roda/plugins/permissions_policy.rb 197 def header_key 198 @report_only ? RodaResponseHeaders::PERMISSIONS_POLICY_REPORT_ONLY : RodaResponseHeaders::PERMISSIONS_POLICY 199 end
header_value()
The header value to use.
[show source]
# File lib/roda/plugins/permissions_policy.rb 202 def header_value 203 return @header_value if @header_value 204 205 s = String.new 206 @opts.each do |k, vs| 207 s << k << "=" 208 209 if vs == :all 210 s << '*, ' 211 else 212 s << '(' 213 vs.each{|v| append_formatted_value(s, v)} 214 s.chop! unless vs.empty? 215 s << '), ' 216 end 217 end 218 s.chop! 219 s.chop! 220 @header_value = s 221 end
report_only(report=true)
Set whether the Permissions-Policy-Report-Only header instead of the default Permissions-Policy header.
[show source]
# File lib/roda/plugins/permissions_policy.rb 225 def report_only(report=true) 226 @report_only = report 227 end
report_only?()
Whether this policy uses report only mode.
[show source]
# File lib/roda/plugins/permissions_policy.rb 230 def report_only? 231 !!@report_only 232 end
set_header(headers)
Set the current policy in the headers hash. If no settings have been made in the policy, does not set a header.
[show source]
# File lib/roda/plugins/permissions_policy.rb 236 def set_header(headers) 237 return if @opts.empty? 238 headers[header_key] ||= header_value 239 end