Represents a permissions policy.
Methods
Public Class
Public Instance
Public Class methods
new()
[show source]
# File lib/roda/plugins/permissions_policy.rb 173 def initialize 174 clear 175 end
Public Instance methods
clear()
Clear all settings, useful to remove any inherited settings.
[show source]
# File lib/roda/plugins/permissions_policy.rb 178 def clear 179 @opts = {} 180 end
freeze()
Do not allow future modifications to any settings.
[show source]
# File lib/roda/plugins/permissions_policy.rb 183 def freeze 184 @opts.freeze 185 header_value.freeze 186 super 187 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 190 def header_key 191 @report_only ? RodaResponseHeaders::PERMISSIONS_POLICY_REPORT_ONLY : RodaResponseHeaders::PERMISSIONS_POLICY 192 end
header_value()
The header value to use.
[show source]
# File lib/roda/plugins/permissions_policy.rb 195 def header_value 196 return @header_value if @header_value 197 198 s = String.new 199 @opts.each do |k, vs| 200 s << k << "=" 201 202 if vs == :all 203 s << '*, ' 204 else 205 s << '(' 206 vs.each{|v| append_formatted_value(s, v)} 207 s.chop! unless vs.empty? 208 s << '), ' 209 end 210 end 211 s.chop! 212 s.chop! 213 @header_value = s 214 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 218 def report_only(report=true) 219 @report_only = report 220 end
report_only?()
Whether this policy uses report only mode.
[show source]
# File lib/roda/plugins/permissions_policy.rb 223 def report_only? 224 !!@report_only 225 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 229 def set_header(headers) 230 return if @opts.empty? 231 headers[header_key] ||= header_value 232 end