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
- #==(o) ⇒ Object
- #append(new_hash) ⇒ Object
- #directive_value(directive) ⇒ Object (also: #[])
- #dup ⇒ Object
- #initialize(hash) ⇒ Object
- #merge(new_hash) ⇒ Object
- #merge!(new_hash) ⇒ Object
- #modified? ⇒ Boolean
- #opt_out? ⇒ Boolean
- #to_h ⇒ Object
- #update_directive(directive, value) ⇒ Object (also: #[]=)
Class Method Details
.included(base) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/secure_headers/headers/content_security_policy_config.rb', line 3 def self.included(base) base.send(:attr_writer, :modified) 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
63 64 65 |
# File 'lib/secure_headers/headers/content_security_policy_config.rb', line 63 def ==(o) self.class == o.class && self.to_h == o.to_h end |
#append(new_hash) ⇒ Object
44 45 46 |
# File 'lib/secure_headers/headers/content_security_policy_config.rb', line 44 def append(new_hash) from_hash(ContentSecurityPolicy.combine_policies(self.to_h, new_hash)) end |
#directive_value(directive) ⇒ Object Also known as: []
26 27 28 29 30 |
# File 'lib/secure_headers/headers/content_security_policy_config.rb', line 26 def directive_value(directive) if self.class.attrs.include?(directive) self.send(directive) end end |
#dup ⇒ Object
55 56 57 |
# File 'lib/secure_headers/headers/content_security_policy_config.rb', line 55 def dup self.class.new(self.to_h) end |
#initialize(hash) ⇒ Object
17 18 19 20 |
# File 'lib/secure_headers/headers/content_security_policy_config.rb', line 17 def initialize(hash) from_hash(hash) @modified = false end |
#merge(new_hash) ⇒ Object
36 37 38 |
# File 'lib/secure_headers/headers/content_security_policy_config.rb', line 36 def merge(new_hash) ContentSecurityPolicy.combine_policies(self.to_h, new_hash) end |
#merge!(new_hash) ⇒ Object
40 41 42 |
# File 'lib/secure_headers/headers/content_security_policy_config.rb', line 40 def merge!(new_hash) from_hash(new_hash) end |
#modified? ⇒ Boolean
32 33 34 |
# File 'lib/secure_headers/headers/content_security_policy_config.rb', line 32 def modified? @modified end |
#opt_out? ⇒ Boolean
59 60 61 |
# File 'lib/secure_headers/headers/content_security_policy_config.rb', line 59 def opt_out? false end |
#to_h ⇒ Object
48 49 50 51 52 53 |
# File 'lib/secure_headers/headers/content_security_policy_config.rb', line 48 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: []=
22 23 24 |
# File 'lib/secure_headers/headers/content_security_policy_config.rb', line 22 def update_directive(directive, value) self.send("#{directive}=", value) end |