Class: Coppertone::RequestContext

Inherits:
Object
  • Object
show all
Defined in:
lib/coppertone/request_context.rb

Overview

A container for information that should span the lifetime of an SPF check. This include the DNS client, the locale used for error messages, limits for DNS requests of different types, and limiters that ensure those limits are not exceeded across the lifetime of the request.

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ RequestContext

Returns a new instance of RequestContext.



10
11
12
# File 'lib/coppertone/request_context.rb', line 10

def initialize(options = {})
  @options = (options || {}).dup
end

Instance Method Details

#dns_clientObject



34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/coppertone/request_context.rb', line 34

def dns_client
  @dns_client ||=
    if @options[:dns_client]
      @options[:dns_client]
    elsif @options[:dns_client_class]
      @options[:dns_client_class].new
    elsif Coppertone.config.dns_client_class
      Coppertone.config.dns_client_class.new
    else
      DNSAdapter::ResolvClient.new
    end
end

#dns_lookups_per_mx_mechanism_limitObject



22
23
24
# File 'lib/coppertone/request_context.rb', line 22

def dns_lookups_per_mx_mechanism_limit
  config_value(:dns_lookups_per_mx_mechanism_limit)
end

#dns_lookups_per_ptr_mechanism_limitObject



26
27
28
# File 'lib/coppertone/request_context.rb', line 26

def dns_lookups_per_ptr_mechanism_limit
  config_value(:dns_lookups_per_ptr_mechanism_limit)
end

#message_localeObject



30
31
32
# File 'lib/coppertone/request_context.rb', line 30

def message_locale
  config_value(:message_locale)
end

#register_dns_lookup_termObject



14
15
16
# File 'lib/coppertone/request_context.rb', line 14

def register_dns_lookup_term
  dns_lookup_term_count_limiter.increment!
end

#register_void_dns_resultObject



18
19
20
# File 'lib/coppertone/request_context.rb', line 18

def register_void_dns_result
  void_dns_result_count_limiter.increment!
end