class ActionDispatch::PermissionsPolicy
Constants
- DIRECTIVES
List of available permissions can be found at github.com/w3c/webappsec-permissions-policy/blob/master/features.md#policy-controlled-features
- MAPPINGS
Attributes
directives[R]
Public Class Methods
new() { |self| ... }
click to toggle source
# File lib/action_dispatch/http/permissions_policy.rb, line 90 def initialize @directives = {} yield self if block_given? end
Public Instance Methods
build(context = nil)
click to toggle source
# File lib/action_dispatch/http/permissions_policy.rb, line 109 def build(context = nil) build_directives(context).compact.join("; ") end
initialize_copy(other)
click to toggle source
# File lib/action_dispatch/http/permissions_policy.rb, line 95 def initialize_copy(other) @directives = other.directives.deep_dup end
Private Instance Methods
apply_mapping(source)
click to toggle source
# File lib/action_dispatch/http/permissions_policy.rb, line 127 def apply_mapping(source) MAPPINGS.fetch(source) do raise ArgumentError, "Unknown HTTP permissions policy source mapping: #{source.inspect}" end end
apply_mappings(sources)
click to toggle source
# File lib/action_dispatch/http/permissions_policy.rb, line 114 def apply_mappings(sources) sources.map do |source| case source when Symbol apply_mapping(source) when String, Proc source else raise ArgumentError, "Invalid HTTP permissions policy source: #{source.inspect}" end end end
build_directive(sources, context)
click to toggle source
# File lib/action_dispatch/http/permissions_policy.rb, line 145 def build_directive(sources, context) sources.map { |source| resolve_source(source, context) } end
build_directives(context)
click to toggle source
# File lib/action_dispatch/http/permissions_policy.rb, line 133 def build_directives(context) @directives.map do |directive, sources| if sources.is_a?(Array) "#{directive} #{build_directive(sources, context).join(' ')}" elsif sources directive else nil end end end
resolve_source(source, context)
click to toggle source
# File lib/action_dispatch/http/permissions_policy.rb, line 149 def resolve_source(source, context) case source when String source when Symbol source.to_s when Proc if context.nil? raise RuntimeError, "Missing context for the dynamic permissions policy source: #{source.inspect}" else context.instance_exec(&source) end else raise RuntimeError, "Unexpected permissions policy source: #{source.inspect}" end end