module SecureHeaders::DynamicConfig
Public Class Methods
new(hash)
click to toggle source
# File lib/secure_headers/headers/content_security_policy_config.rb, line 4 def initialize(hash) @config = {} from_hash(hash) end
Public Instance Methods
==(o)
click to toggle source
# File lib/secure_headers/headers/content_security_policy_config.rb, line 49 def ==(o) self.class == o.class && self.to_h == o.to_h end
append(new_hash)
click to toggle source
# File lib/secure_headers/headers/content_security_policy_config.rb, line 33 def append(new_hash) from_hash(ContentSecurityPolicy.combine_policies(self.to_h, new_hash)) end
directive_value(directive)
click to toggle source
# File lib/secure_headers/headers/content_security_policy_config.rb, line 18 def directive_value(directive) # No need to check attrs, as we only assign valid keys @config[directive] end
Also aliased as: []
dup()
click to toggle source
# File lib/secure_headers/headers/content_security_policy_config.rb, line 41 def dup self.class.new(self.to_h) end
initialize_copy(hash)
click to toggle source
# File lib/secure_headers/headers/content_security_policy_config.rb, line 10 def initialize_copy(hash) @config = hash.to_h end
merge(new_hash)
click to toggle source
# File lib/secure_headers/headers/content_security_policy_config.rb, line 23 def merge(new_hash) new_config = self.dup new_config.send(:from_hash, new_hash) new_config end
merge!(new_hash)
click to toggle source
# File lib/secure_headers/headers/content_security_policy_config.rb, line 29 def merge!(new_hash) from_hash(new_hash) end
opt_out?()
click to toggle source
# File lib/secure_headers/headers/content_security_policy_config.rb, line 45 def opt_out? false end
to_h()
click to toggle source
# File lib/secure_headers/headers/content_security_policy_config.rb, line 37 def to_h @config.dup end
update_directive(directive, value)
click to toggle source
# File lib/secure_headers/headers/content_security_policy_config.rb, line 14 def update_directive(directive, value) @config[directive] = value end
Also aliased as: []=
Private Instance Methods
from_hash(hash)
click to toggle source
# File lib/secure_headers/headers/content_security_policy_config.rb, line 57 def from_hash(hash) hash.each_pair do |k, v| next if v.nil? if self.class.attrs.include?(k) write_attribute(k, v) else raise ContentSecurityPolicyConfigError, "Unknown config directive: #{k}=#{v}" end end end
write_attribute(attr, value)
click to toggle source
# File lib/secure_headers/headers/content_security_policy_config.rb, line 69 def write_attribute(attr, value) value = value.dup if PolicyManagement::DIRECTIVE_VALUE_TYPES[attr] == :source_list if value.nil? @config.delete(attr) else @config[attr] = value end end