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 16 17 18 19 20 |
# 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) value = value.dup if PolicyManagement::DIRECTIVE_VALUE_TYPES[attr] == :source_list prev_value = self.instance_variable_get("@#{attr}") self.instance_variable_set("@#{attr}", value) if prev_value != self.instance_variable_get("@#{attr}") @modified = true end else raise ContentSecurityPolicyConfigError, "Unknown config directive: #{attr}=#{value}" end end end end |
Instance Method Details
#==(o) ⇒ Object
67 68 69 |
# File 'lib/secure_headers/headers/content_security_policy_config.rb', line 67 def ==(o) self.class == o.class && self.to_h == o.to_h end |
#append(new_hash) ⇒ Object
49 50 51 |
# File 'lib/secure_headers/headers/content_security_policy_config.rb', line 49 def append(new_hash) from_hash(ContentSecurityPolicy.combine_policies(self.to_h, new_hash)) end |
#directive_value(directive) ⇒ Object Also known as: []
31 32 33 34 35 |
# File 'lib/secure_headers/headers/content_security_policy_config.rb', line 31 def directive_value(directive) if self.class.attrs.include?(directive) self.send(directive) end end |
#dup ⇒ Object
59 60 61 |
# File 'lib/secure_headers/headers/content_security_policy_config.rb', line 59 def dup self.class.new(self.to_h) end |
#initialize(hash) ⇒ Object
22 23 24 25 |
# File 'lib/secure_headers/headers/content_security_policy_config.rb', line 22 def initialize(hash) from_hash(hash) @modified = false end |
#merge(new_hash) ⇒ Object
41 42 43 |
# File 'lib/secure_headers/headers/content_security_policy_config.rb', line 41 def merge(new_hash) ContentSecurityPolicy.combine_policies(self.to_h, new_hash) end |
#merge!(new_hash) ⇒ Object
45 46 47 |
# File 'lib/secure_headers/headers/content_security_policy_config.rb', line 45 def merge!(new_hash) from_hash(new_hash) end |
#modified? ⇒ Boolean
37 38 39 |
# File 'lib/secure_headers/headers/content_security_policy_config.rb', line 37 def modified? @modified end |
#opt_out? ⇒ Boolean
63 64 65 |
# File 'lib/secure_headers/headers/content_security_policy_config.rb', line 63 def opt_out? false end |
#to_h ⇒ Object
53 54 55 56 57 |
# File 'lib/secure_headers/headers/content_security_policy_config.rb', line 53 def to_h self.class.attrs.each_with_object({}) do |key, hash| hash[key] = self.send(key) end.reject { |_, v| v.nil? } end |
#update_directive(directive, value) ⇒ Object Also known as: []=
27 28 29 |
# File 'lib/secure_headers/headers/content_security_policy_config.rb', line 27 def update_directive(directive, value) self.send("#{directive}=", value) end |