Class: Roda::RodaPlugins::PermissionsPolicy::Policy
- Inherits:
-
Object
- Object
- Roda::RodaPlugins::PermissionsPolicy::Policy
- Defined in:
- lib/roda/plugins/permissions_policy.rb
Overview
Represents a permissions policy.
Instance Method Summary collapse
-
#clear ⇒ Object
Clear all settings, useful to remove any inherited settings.
-
#freeze ⇒ Object
Do not allow future modifications to any settings.
-
#header_key ⇒ Object
The header name to use, depends on whether report only mode has been enabled.
-
#header_value ⇒ Object
The header value to use.
-
#initialize ⇒ Policy
constructor
A new instance of Policy.
-
#report_only(report = true) ⇒ Object
Set whether the Permissions-Policy-Report-Only header instead of the default Permissions-Policy header.
-
#report_only? ⇒ Boolean
Whether this policy uses report only mode.
-
#set_header(headers) ⇒ Object
Set the current policy in the headers hash.
Constructor Details
#initialize ⇒ Policy
Returns a new instance of Policy.
173 174 175 |
# File 'lib/roda/plugins/permissions_policy.rb', line 173 def initialize clear end |
Instance Method Details
#clear ⇒ Object
Clear all settings, useful to remove any inherited settings.
178 179 180 |
# File 'lib/roda/plugins/permissions_policy.rb', line 178 def clear @opts = {} end |
#freeze ⇒ Object
Do not allow future modifications to any settings.
183 184 185 186 187 |
# File 'lib/roda/plugins/permissions_policy.rb', line 183 def freeze @opts.freeze header_value.freeze super end |
#header_key ⇒ Object
The header name to use, depends on whether report only mode has been enabled.
190 191 192 |
# File 'lib/roda/plugins/permissions_policy.rb', line 190 def header_key @report_only ? RodaResponseHeaders::PERMISSIONS_POLICY_REPORT_ONLY : RodaResponseHeaders::PERMISSIONS_POLICY end |
#header_value ⇒ Object
The header value to use.
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 |
# File 'lib/roda/plugins/permissions_policy.rb', line 195 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 |
#report_only(report = true) ⇒ Object
Set whether the Permissions-Policy-Report-Only header instead of the default Permissions-Policy header.
218 219 220 |
# File 'lib/roda/plugins/permissions_policy.rb', line 218 def report_only(report=true) @report_only = report end |
#report_only? ⇒ Boolean
Whether this policy uses report only mode.
223 224 225 |
# File 'lib/roda/plugins/permissions_policy.rb', line 223 def report_only? !!@report_only end |
#set_header(headers) ⇒ Object
Set the current policy in the headers hash. If no settings have been made in the policy, does not set a header.
229 230 231 232 |
# File 'lib/roda/plugins/permissions_policy.rb', line 229 def set_header(headers) return if @opts.empty? headers[header_key] ||= header_value end |