Module: SecureHeaders::DynamicConfig

Included in:
ContentSecurityPolicyConfig
Defined in:
lib/secure_headers/headers/content_security_policy_config.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/secure_headers/headers/content_security_policy_config.rb', line 4

def self.included(base)
  base.send(:attr_reader, *base.attrs)
  base.attrs.each do |attr|
    base.send(:define_method, "#{attr}=") do |value|
      if self.class.attrs.include?(attr)
        write_attribute(attr, value)
      else
        raise ContentSecurityPolicyConfigError, "Unknown config directive: #{attr}=#{value}"
      end
    end
  end
end

Instance Method Details

#==(o) ⇒ Object



93
94
95
# File 'lib/secure_headers/headers/content_security_policy_config.rb', line 93

def ==(o)
  self.class == o.class && self.to_h == o.to_h
end

#append(new_hash) ⇒ Object



74
75
76
# File 'lib/secure_headers/headers/content_security_policy_config.rb', line 74

def append(new_hash)
  from_hash(ContentSecurityPolicy.combine_policies(self.to_h, new_hash))
end

#directive_value(directive) ⇒ Object Also known as: []



58
59
60
61
62
# File 'lib/secure_headers/headers/content_security_policy_config.rb', line 58

def directive_value(directive)
  if self.class.attrs.include?(directive)
    self.send(directive)
  end
end

#dupObject



85
86
87
# File 'lib/secure_headers/headers/content_security_policy_config.rb', line 85

def dup
  self.class.new(self.to_h)
end

#initialize(hash) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/secure_headers/headers/content_security_policy_config.rb', line 17

def initialize(hash)
  @base_uri = nil
  @block_all_mixed_content = nil
  @child_src = nil
  @connect_src = nil
  @default_src = nil
  @font_src = nil
  @form_action = nil
  @frame_ancestors = nil
  @frame_src = nil
  @img_src = nil
  @manifest_src = nil
  @media_src = nil
  @navigate_to = nil
  @object_src = nil
  @plugin_types = nil
  @prefetch_src = nil
  @preserve_schemes = nil
  @report_only = nil
  @report_uri = nil
  @require_sri_for = nil
  @sandbox = nil
  @script_nonce = nil
  @script_src = nil
  @script_src_elem = nil
  @script_src_attr = nil
  @style_nonce = nil
  @style_src = nil
  @style_src_elem = nil
  @style_src_attr = nil
  @worker_src = nil
  @upgrade_insecure_requests = nil
  @disable_nonce_backwards_compatibility = nil

  from_hash(hash)
end

#merge(new_hash) ⇒ Object



64
65
66
67
68
# File 'lib/secure_headers/headers/content_security_policy_config.rb', line 64

def merge(new_hash)
  new_config = self.dup
  new_config.send(:from_hash, new_hash)
  new_config
end

#merge!(new_hash) ⇒ Object



70
71
72
# File 'lib/secure_headers/headers/content_security_policy_config.rb', line 70

def merge!(new_hash)
  from_hash(new_hash)
end

#opt_out?Boolean

Returns:

  • (Boolean)


89
90
91
# File 'lib/secure_headers/headers/content_security_policy_config.rb', line 89

def opt_out?
  false
end

#to_hObject



78
79
80
81
82
83
# File 'lib/secure_headers/headers/content_security_policy_config.rb', line 78

def to_h
  self.class.attrs.each_with_object({}) do |key, hash|
    value = self.send(key)
    hash[key] = value unless value.nil?
  end
end

#update_directive(directive, value) ⇒ Object Also known as: []=



54
55
56
# File 'lib/secure_headers/headers/content_security_policy_config.rb', line 54

def update_directive(directive, value)
  self.send("#{directive}=", value)
end