Class: Rack::BlacklistCookies::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/blacklist_cookies/configuration.rb

Overview

Configuration defaults to an empty hash if it has not been set.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



8
9
10
11
# File 'lib/rack/blacklist_cookies/configuration.rb', line 8

def initialize
  @request_blacklist = {}
  @response_blacklist = {}
end

Instance Attribute Details

#request_blacklistObject

Returns the value of attribute request_blacklist.



6
7
8
# File 'lib/rack/blacklist_cookies/configuration.rb', line 6

def request_blacklist
  @request_blacklist
end

#response_blacklistObject

Returns the value of attribute response_blacklist.



6
7
8
# File 'lib/rack/blacklist_cookies/configuration.rb', line 6

def response_blacklist
  @response_blacklist
end

Instance Method Details

#resetObject



13
14
15
16
# File 'lib/rack/blacklist_cookies/configuration.rb', line 13

def reset
  @request_blacklist = {}
  @response_blacklist = {}
end

#validateObject

rubocop:disable MethodLength



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/rack/blacklist_cookies/configuration.rb', line 19

def validate
  [@request_blacklist, @response_blacklist].each do |blacklist|
    raise ConfigurationError, "Blacklist is not a hash" unless blacklist.is_a?(Hash)
    blacklist.each do |route, cookie_list|
      raise ConfigurationError, "Blacklist key is not a string" unless route.is_a?(String)
      raise ConfigurationError, "Blacklist value is not an array" unless cookie_list.is_a?(Array)
      raise ConfigurationError, "Blacklist key is not a URL path" unless route.start_with?("/")
      cookie_list.each do |cookie_name|
        raise ConfigurationError, "Blacklist cookie is not a valid name string" unless cookie_name.is_a?(String)
      end
    end
  end
end