class Roda::RodaPlugins::PermissionsPolicy::Policy

  1. lib/roda/plugins/permissions_policy.rb
Superclass: Object

Represents a permissions policy.

Methods

Public Class

  1. new

Public Instance

  1. clear
  2. freeze
  3. header_key
  4. header_value
  5. report_only
  6. report_only?
  7. set_header

Public Class methods

new()
[show source]
    # File lib/roda/plugins/permissions_policy.rb
176 def initialize
177   clear
178 end

Public Instance methods

clear()

Clear all settings, useful to remove any inherited settings.

[show source]
    # File lib/roda/plugins/permissions_policy.rb
181 def clear
182   @opts = {}
183 end
freeze()

Do not allow future modifications to any settings.

[show source]
    # File lib/roda/plugins/permissions_policy.rb
186 def freeze
187   @opts.freeze
188   header_value.freeze
189   super
190 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
193 def header_key
194   @report_only ? RodaResponseHeaders::PERMISSIONS_POLICY_REPORT_ONLY : RodaResponseHeaders::PERMISSIONS_POLICY
195 end
header_value()

The header value to use.

[show source]
    # File lib/roda/plugins/permissions_policy.rb
198 def header_value
199   return @header_value if @header_value
200 
201   s = String.new
202   @opts.each do |k, vs|
203     s << k << "="
204 
205     if vs == :all
206       s << '*, '
207     else
208       s << '('
209       vs.each{|v| append_formatted_value(s, v)}
210       s.chop! unless vs.empty?
211       s << '), '
212     end
213   end
214   s.chop!
215   s.chop!
216   @header_value = s
217 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
221 def report_only(report=true)
222   @report_only = report
223 end
report_only?()

Whether this policy uses report only mode.

[show source]
    # File lib/roda/plugins/permissions_policy.rb
226 def report_only?
227   !!@report_only
228 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
232 def set_header(headers)
233   return if @opts.empty?
234   headers[header_key] ||= header_value
235 end